简体   繁体   中英

spring boot convert datetime with timezone to '0' timezone in server

I want to store all date time and when a user wants to get information. The server must to return data with datetime and 3rd party devices (like Android , IOS, Web apps) should convert that datetime for specific timezone. The basic goal is store all date timezone with "0" timezone

You can use Java8 ZonedDateTime to get time in UTC. My assumption is 0 timezone means UTC

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

To convert ZontedDateTime , You can put GMT,US/Central etc in the config file

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM