Datetime t = Datetime.now();
    System.debug(t.format('HH hh kk KK'));


13:37:57:233 USER_DEBUG [16]|DEBUG|2013-05-17 11:37:58

13:37:57:234 USER_DEBUG [17]|DEBUG|04 04 04 04

H,h,k,K all returned 04, but I'm pretty sure it should be 11 instead!

1 Answer 1


The format function convert the datetime variable to local time.

datetime.now() is showing GMT.

format|String|Converts the date to the local time zone and returns the converted date as a formatted string using the locale of the context user. If the time zone cannot be determined, GMT is used.

More details: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_datetime.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .