Java convert millisecond timestamp to date with respect to given timezone

后端 未结 4 1651
北海茫月
北海茫月 2021-01-15 12:58

I have seen many resources on this but one thing I cant get is when converting the millisecond timestamp, how I add a corresponding time zone, during the conversion process.

4条回答
  •  礼貌的吻别
    2021-01-15 13:47

    Not exactly what your looking for but close

    String timeZone = "America/Los_Angeles"
    TimeZone tz = TimeZone.getTimeZone(timeZone);
    SimpleDateFormat sdf = new SimpleDateFormat("EEEEE MMMMM d hh:mm a");
    sdf.setTimeZone(tz);
    
    Date localizedTime = sdf.format(new Date());
    

    If you keep the localization strings instead of the offsets this will work. Or you can make a map.

提交回复
热议问题