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

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.