protected static Date getZonedTime(Date time,ZoneId toZoneId) {
System.out.println("***********************************************************************************");
ZonedDateTime zdt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(time.getTime()), ZoneId.of("UTC"));
System.out.println(zdt);
Date date = new Date(zdt.withZoneSameInstant(ZoneId.of("Asia/Kolkata")).toInstant().toEpochMilli());
System.out.println(date);
System.out.println("***********************************************************************************");
return date;
}
- Why is this code behaving differently when run in local machine vs google cloud function ?
Objective of the code is to convert time to clients (of http request) timezone (time is retrieved from mysql where its stored in UTC)
Output in local JVM
input = 2020-09-01T16:54:20.704Z[UTC]
output = Tue Sep 01 22:24:20 IST 2020
Output from Google Cloud function
input = invoked getZonedTime=2020-09-01 15:10:31.0
output = returning getZonedTime=Tue Sep 01 15:10:31 UTC 2020
Was expecting the time at the new timezone (with the same instance of time of the date object passed) be returned.
Thanks