Convert Date/Time for given Timezone - java

前端 未结 16 2436
孤城傲影
孤城傲影 2020-11-22 12:36

I want to convert this GMT time stamp to GMT+13:

2011-10-06 03:35:05

I have tried about 100 different combinations of DateFormat, TimeZone,

16条回答
  •  心在旅途
    2020-11-22 12:46

    display date and time for all timezones

    import java.util.Calendar;
    import java.util.TimeZone;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    
    
    
    static final String ISO8601 = "yyyy-MM-dd'T'HH:mm:ssZ";
    DateFormat dateFormat = new SimpleDateFormat(ISO8601);
    Calendar c = Calendar.getInstance();
    String formattedTime;
    for (String availableID : TimeZone.getAvailableIDs()) {
        dateFormat.setTimeZone(TimeZone.getTimeZone(availableID));
        formattedTime = dateFormat.format(c.getTime());
        System.out.println(formattedTime + " " + availableID);
    }
    

提交回复
热议问题