日付関連をずらっとまとめる。
【当日】
Date.today()
【本日から±○日、±○ヶ月、±○年】
・1日後 Date.today().addDays(1); ・1ヶ月前 Date.today().addMonths(-1); ・2年後 Date.today().addYears(2);
【yyyy-MM-ddをyyyy年MM月dd日に変えたい場合】
(例)
オブジェクトAPI名:objTest__c
項目名:
項目API名 | 型 |
testDate__c | 日付 |
testDateTime__c | 日付/時間 |
・型:日付の場合
Datetime.newInstance(objTest__c.testDate__c.year(), objTest__c.testDate__c.month(), objTest__c.testDate__c.day()).format('yyyy年MM月dd日');
・型:日付/時間の場合
objTest__c.testDateTime__c.format('yyyy年MM月dd日');
【集計した時間の単位を変えたい】
数値項目で集計している値をhh時間mm分に変える。
(例)数値100を「1時間40分」に変換する。
Dechimal minTotalTime = 100; String strTotalTime = (minTotalTime / 60).setscale(2).round(System.RoundingMode/DOWN) + '時間' + math.mod(minTotalTime.intValue(), 60) + '分';
【日本時間の設定】
Datetime.format('yyyy/MM/dd HH:mm', 'JST');
JSTは日本時間に設定。設定しない場合は-9時間となる。