谷歌云功能时区对话

时间:2020-09-01 17:12:53

标签: java mysql google-cloud-functions zoneddatetime

    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;
    }
  • 在本地计算机和Google云功能中运行时,为什么这段代码的行为有所不同?

代码的目标是将时间转换为(http请求的)客户端时区(从存储在UTC中的mysql检索时间)

本地JVM中的输出

input = 2020-09-01T16:54:20.704Z [UTC]

output = Tue Sep 01 22:24:20 IST 2020

Google Cloud功能的输出

input = 调用了getZonedTime = 2020-09-01 15:10:3​​1.0

output = returning getZonedTime = Tue Sep 01 15:10:31 UTC 2020

期望返回新时区的时间(具有与传递的日期对象相同的时间实例)。

谢谢

0 个答案:

没有答案