gpt4 book ai didi

java - Spring Boot将带有时区的日期时间转换为服务器中的 '0'时区

转载 作者:太空宇宙 更新时间:2023-11-04 10:11:28 27 4
gpt4 key购买 nike

我想存储所有日期时间以及用户想要获取信息的时间。服务器必须返回带有日期时间的数据,并且第 3 方设备(例如 Android、IOS、Web 应用程序)应将该日期时间转换为特定时区。基本目标是存储所有带有“0”时区的日期时区

最佳答案

您可以使用 Java8 ZonedDateTime 获取 UTC 时间。我的假设是 0 时区表示 UTC

ZonedDateTime.now(ZoneOffset.UTC);// This will give current time in UTC

要转换 ZontedDateTime ,您可以将 GMT、US/Central 等放入配置文件中

public static ZonedDateTime getDateinTimeZone(String timeZone,String dateInSting )
{
return ZonedDateTime.parse(dateInSting).now(ZoneId.of(timeZone));
}

关于java - Spring Boot将带有时区的日期时间转换为服务器中的 '0'时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52255872/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com