Timezone conversion

后端 未结 12 1613
一向
一向 2020-11-22 11:25

I need to convert from one timezone to another timezone in my project.

I am able to convert from my current timezone to another but not from a different timezone to

12条回答
  •  猫巷女王i
    2020-11-22 11:57

        Date date = new Date();
        String formatPattern = ....;
        SimpleDateFormat sdf = new SimpleDateFormat(formatPattern);
    
        TimeZone T1;
        TimeZone T2;
    
        // set the Calendar of sdf to timezone T1
        sdf.setTimeZone(T1);
        System.out.println(sdf.format(date));
    
        // set the Calendar of sdf to timezone T2
        sdf.setTimeZone(T2);
        System.out.println(sdf.format(date));
    
        // Use the 'calOfT2' instance-methods to get specific info
        // about the time-of-day for date 'date' in timezone T2.
        Calendar calOfT2 = sdf.getCalendar();
    

提交回复
热议问题