List of usage examples for java.util TimeZone getTimeZone
public static TimeZone getTimeZone(ZoneId zoneId)
From source file:Main.java
public static void main(String[] args) { // create a calendar Locale locale1 = Locale.CANADA; TimeZone tz1 = TimeZone.getTimeZone("GMT"); Calendar cal1 = Calendar.getInstance(tz1, locale1); // display time zone for both calendars String tzname1 = tz1.getDisplayName(); String name1 = locale1.getDisplayName(); System.out.println("GMT and Canada: " + tzname1 + " " + name1); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar local = Calendar.getInstance(); Calendar japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan")); japanCal.setTimeInMillis(local.getTimeInMillis()); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println(cal.getTimeZone().getDisplayName()); TimeZone tz = TimeZone.getTimeZone("GMT"); // set the time zone with the given time zone value and print it cal.setTimeZone(tz);//w ww.j av a 2s . c o m System.out.println(cal.getTimeZone().getDisplayName()); }
From source file:Main.java
public static void main(String[] args) throws Exception { SimpleDateFormat broken = new SimpleDateFormat("kk:mm:ss"); broken.setTimeZone(TimeZone.getTimeZone("Etc/UTC")); SimpleDateFormat working = new SimpleDateFormat("HH:mm:ss"); working.setTimeZone(TimeZone.getTimeZone("Etc/UTC")); Date epoch = new Date(0); System.out.println(broken.format(epoch)); System.out.println(working.format(epoch)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar local = Calendar.getInstance(); Calendar japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan")); japanCal.setTimeInMillis(local.getTimeInMillis()); int hour = japanCal.get(Calendar.HOUR); // 3 int minutes = japanCal.get(Calendar.MINUTE); // 0 int seconds = japanCal.get(Calendar.SECOND); // 0 boolean am = japanCal.get(Calendar.AM_PM) == Calendar.AM; // true }
From source file:Main.java
public static void main(String[] args) throws Exception { String inputText = "Nov 10,2015"; TimeZone utc = TimeZone.getTimeZone("UTC"); SimpleDateFormat inputFormat = new SimpleDateFormat("MMM d,yyyy", Locale.US); inputFormat.setTimeZone(utc);//w ww . ja v a 2s .com SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US); outputFormat.setTimeZone(utc); Date parsed = inputFormat.parse(inputText); String outputText = outputFormat.format(parsed); System.out.println(outputText); }
From source file:Main.java
public static void main(String[] argv) throws Exception { // Get the current time in Hong Kong Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("Hongkong")); int hour12 = cal.get(Calendar.HOUR); // 0..11 int minutes = cal.get(Calendar.MINUTE); // 0..59 int seconds = cal.get(Calendar.SECOND); // 0..59 boolean am = cal.get(Calendar.AM_PM) == Calendar.AM; // Get the current hour-of-day at GMT cal.setTimeZone(TimeZone.getTimeZone("GMT")); int hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23 // Get the current local hour-of-day cal.setTimeZone(TimeZone.getDefault()); hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23 }
From source file:Main.java
public static void main(final String[] args) throws ParseException { final SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); f.setTimeZone(TimeZone.getTimeZone("UTC")); System.out.println(f.format(new Date())); }
From source file:Main.java
public static void main(String[] args) { Date d = new Date(); System.out.println(d);//from ww w. j a v a2s.c o m DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); df.setTimeZone(TimeZone.getTimeZone("Australia/Sydney")); System.out.println(df.format(d)); df.setTimeZone(TimeZone.getTimeZone("Europe/London")); System.out.println(df.format(d)); }
From source file:Main.java
public static void main(String[] args) throws Exception { String dStr = "Wed, 05 Jun 2015 00:48:12 GMT"; SimpleDateFormat ft = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z"); Date t = ft.parse(dStr);//from w w w. j ava2 s . co m TimeZone gmt = TimeZone.getTimeZone("England/London"); ft.setTimeZone(gmt); System.out.println(t); System.out.println(ft.format(t)); }