function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hiroji1020hiroji1020 

時間の制御

Apexで時間を制御したいです。

 

現在時間を取得して、たとえば下記のような処理をするにはどうやってCodeすればいいのか教えてください。

 

現在時間が13:00以前の場合 → 処理1

現在時間が13:00以降の場合 → 処理2

Best Answer chosen by Admin (Salesforce Developers) 
Jia HuJia Hu
Try this code,

String localtime = system.now().format();
System.debug(localtime);
String hour = localtime.substring(11, 13);
System.debug(hour);
Integer intHour = Integer.ValueOf(hour);
if(intHour < 13) {
System.debug('現在時間が13:00以前の場合');
} else {
System.debug('現在時間が13:00以降の場合');
}

All Answers

Jia HuJia Hu
Try this code,

String localtime = system.now().format();
System.debug(localtime);
String hour = localtime.substring(11, 13);
System.debug(hour);
Integer intHour = Integer.ValueOf(hour);
if(intHour < 13) {
System.debug('現在時間が13:00以前の場合');
} else {
System.debug('現在時間が13:00以降の場合');
}

This was selected as the best answer
hiroji1020hiroji1020

This is perfect. Thank you so much!!!