How to convert GMT to locale dateTime?

I want to convert the GMT dateTime to locale dateTime as But after converting the format when I am trying to convert that string into dateTime again it is giving me the GMT dateTime.


Your question is not very clear to me, but my two possible interpretations are you want to format the current Datetime according to your locale, or you want to adjust the result to account for the local time zone.

If you just want a locale-specific formatted string to represent the current Datetime, use:

String formatted =;

If you are trying to get the current Datetime in the local time zone, you can use the following code:

Datetime now =;
Integer offset = UserInfo.getTimezone().getOffset(now);
Datetime local = now.addSeconds(offset/1000);

Source : Link , Question Author : Stuart Cole , Answer Author : Przemysław Długoszewski-Tamoń

Leave a Comment