converting a UTC time to a local time zone in Java

后端 未结 2 847
梦毁少年i
梦毁少年i 2021-01-18 17:40

I know this subject has been beaten to death but after searching for a few hours to this problem I had to ask.

My Problem: do calculations on dates on a server based

2条回答
  •  没有蜡笔的小新
    2021-01-18 18:11

    You timezone string is formulated incorrectly. Try this,

    String sign = secondsFromGMT > 0 ? "+" : "-";
    secondsFromGMT = Math.abs(secondsFromGMT);      
    int hours = secondsFromGMT/3600;
    int mins = (secondsFromGMT%3600)/60;
    String zone = String.format("GMT%s%02d:%02d", sign, hours, mins);          
    TimeZone t = TimeZone.getTimeZone(zone);
    

提交回复
热议问题