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?
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`.
Datetime
, not Time
. Remove the call to time()
.
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