How to get local time of different time zones?

前端 未结 7 1168
青春惊慌失措
青春惊慌失措 2020-12-18 19:08

I want to get local time of different time zones using Java code. Based on the time zone passed to the function I need that time zone\'s local time. How to achieve this?

7条回答
  •  一整个雨季
    2020-12-18 20:12

    import java.text.SimpleDateFormat;
    import java.util.GregorianCalendar;
    
    SimpleDateFormat dateFormat = new SimpleDateFormat();
    dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Seoul"));
    GregorianCalendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, 0);
    
    System.out.println(dateFormat.format( cal.getTime()));
    

提交回复
热议问题