Last active
August 29, 2015 14:23
-
-
Save xmonkee/585b6135d08981fb11ee to your computer and use it in GitHub Desktop.
Convert between time zones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* http://www.java2s.com/Code/Java/Development-Class/Converttimebetweentimezone.htm */ | |
import java.util.Calendar; | |
import java.util.GregorianCalendar; | |
import java.util.TimeZone; | |
public class Main { | |
public static void main(String[] args) { | |
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment