Reputation: 1787
I have the following code which gets current time in a certain format. This works perfectly fine locally when I test it out on my laptop.
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS z");
ZonedDateTime date = ZonedDateTime.now();
String timeStamp = formatter.format(date);
This above works locally and the timestamp value is in following format: 2020-02-24 05:23:20.675 MST
But when I push it to production, the format changes to following: 2020-02-24 05:23:20.675 -07:00
I do not have access to the production settings and the team that handles it is in another timezone and will not be able to get them now. Believe it is some setting on their end but is there something I could do such that the format is always like: 2020-02-24 05:23:20.675 MST ?
Please advice, thanks.
Upvotes: 3
Views: 212
Reputation: 59986
You have to specify your time zone, it seems in production you are using a different time zone than the one in local. Beside in your code you don't specify any Zone, for that it took the default Zone.
To solve this, you have to specify the zone :
ZoneId zoneId = ZoneId.of("America/Dawson_Creek"); // specify the zone you want to use
ZonedDateTime date = ZonedDateTime.now(zoneId);
Upvotes: 5