Date and time conversion to some other Timezone in java

后端 未结 10 477
失恋的感觉
失恋的感觉 2020-12-11 21:13

i have written this code to convert the current system date and time to some other timezone. I am not getting any error but i am not getting my output as expected. Like if i

10条回答
  •  暖寄归人
    2020-12-11 21:44

    You can just use "CST6CDT" because in some countries they follow CDT in summer and CST in winter

     public static String getDateInCST() {
                 Calendar calendar = Calendar.getInstance();
                 DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
                 formatter.setTimeZone(TimeZone.getTimeZone( "CST6CDT"));
                 String strdate = formatter.format(calendar.getTime());
                 TimeZone.getAvailableIDs();
                 return strdate;
         }
    

提交回复
热议问题