출처1 : https://coderanch.com/t/386398/java/System-Timezone

출처2 : https://stackoverflow.com/questions/6567923/timezone-conversion#6567960


//get local timezone id

TimeZone tz = Calendar.getInstance().getTimeZone();

System.out.println(tz.getDisplayName()); // (i.e. Moscow Standard Time)

System.out.println(tz.getID()); // (i.e. Europe/Moscow)


//convert timezone

Calendar localTime = Calendar.getInstance();

localTime.set(Calendar.HOUR, 17);

localTime.set(Calendar.MINUTE, 15);

localTime.set(Calendar.SECOND, 20);

 

int hour = localTime.get(Calendar.HOUR);

int minute = localTime.get(Calendar.MINUTE);

int second = localTime.get(Calendar.SECOND);

 

System.out.printf("Local time  : %02d:%02d:%02d\n", hour, minute, second);

 

Calendar germanyTime = new GregorianCalendar(TimeZone.getTimeZone("Germany"));

germanyTime.setTimeInMillis(localTime.getTimeInMillis());

hour = germanyTime.get(Calendar.HOUR);

minute = germanyTime.get(Calendar.MINUTE);

second = germanyTime.get(Calendar.SECOND);

 

System.out.printf("Germany time: %02d:%02d:%02d\n", hour, minute, second);

        



Posted by motolies
,