String day = string.valueOf(system.now().day());
String month = string.valueOf(system.now().month());
String hour = string.valueOf(system.now().hour());
String minute = string.valueOf(system.now().minute());
String second = string.valueOf(system.now().second());
String year = string.valueOf(system.now().year());

String strTime = year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second ;


output 1: 2015-7-7 14:5:55

output 2: 2015-07-07 08:35:55


  • Try looking at Json.serialize() to see underlying value irrespective of timezone – bigassforce Jul 7 '15 at 10:26

DateTime objects have built-in support for the user's timezone. So DateTime.hour:

Returns the hour component of a Datetime in the local time zone of the context user.

DateTime.format also includes the timezone offset but just doing a default DateTime conversion to a string looks like it presents the underlying GMT value.


System.now() returns the DateTime in GMT time zone, whereas System.now().hour() is the method of DateTime class, which returns the local time zone of the context user.

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.