1

This code record.Start_Time__c.time() is giving me 11:30:00.000Z but I just want 11:30am or pm or army time might be ok too.

This code currStartDate.Date() is giving me 2015-07-08 00:00:00 but I just want 2015-07-08

What do I need to do?

3

Take a look at Java SimpleDateFormat.

system.debug(Datetime.now().format('hh:mmaa')); // 08:24AM
system.debug(Datetime.now().format('hh:mm:ss aa')); // 08:24:07 AM 
system.debug(Datetime.now().format('yyyy-MM-dd'));  // 2016-05-31

Note that these are methods on Datetime, so you should not call date() or time() on your Datetime value before doing the formatting, as doing so will change the type to Date or Time respectively, and neither of these types have a format method defined`.

3
  • It won't allow me to do this record.Start_Time__c.time().format('hh:mm:ss aa') – Apex N-u-b May 31 '16 at 14:36
  • @ApexN-u-b It's a method on Datetime, not Time. Remove the call to time(). – Adrian Larson May 31 '16 at 14:37
  • My apologies. I saw victors answer and just pasted it in before I saw your explanation. You were correct. Thank you both. – Apex N-u-b May 31 '16 at 14:44
1

You should be able to use below lines,

record.Start_Time__c.format('hh:mm a');    //11:30 AM
currStartDate.format('yyyy-MM-dd');        //2015-07-08
1
  • 1
    How is this even different from my answer? – Adrian Larson May 31 '16 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.