1 package com.freemindcafe.timezone.sample3;
3 import java.text.DateFormat;
4 import java.text.SimpleDateFormat;
5 import java.util.Calendar;
7 import java.util.TimeZone;
9 import junit.framework.Assert;
11 import org.junit.Test;
17 TimeZone tz = TimeZone.getTimeZone(
"Asia/Calcutta");
18 Assert.assertEquals(
"India Standard Time",tz.getDisplayName());
19 Calendar cal = Calendar.getInstance(tz);
20 System.out.printf(
"%02d:%02d:%02d", cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
25 TimeZone tz = TimeZone.getTimeZone(
"IST");
26 Assert.assertEquals(
"India Standard Time",tz.getDisplayName());
27 Calendar cal = Calendar.getInstance(tz);
28 System.out.printf(
"%02d:%02d:%02d", cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
33 TimeZone tz = TimeZone.getTimeZone(
"Etc/GMT+5:30");
34 Assert.assertEquals(
"Greenwich Mean Time",tz.getDisplayName());
35 Calendar cal = Calendar.getInstance(tz);
36 System.out.printf(
"%02d:%02d:%02d", cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
41 TimeZone tz = TimeZone.getTimeZone(
"Etc/GMT+5");
42 Assert.assertEquals(
"GMT-05:00",tz.getDisplayName());
43 Calendar cal = Calendar.getInstance(tz);
44 System.out.printf(
"%02d:%02d:%02d", cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
49 TimeZone tz = TimeZone.getTimeZone(
"Etc/GMT-5");
50 Assert.assertEquals(
"GMT+05:00",tz.getDisplayName());
51 Calendar cal = Calendar.getInstance(tz);
52 System.out.printf(
"%02d:%02d:%02d", cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
57 TimeZone tz = TimeZone.getTimeZone(
"GMT+5:30");
58 Assert.assertEquals(
"GMT+05:30",tz.getDisplayName());
59 Calendar cal = Calendar.getInstance(tz);
60 System.out.printf(
"%02d:%02d:%02d", cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
65 public void test7()
throws Exception{
67 DateFormat fmt1 =
new SimpleDateFormat(
"M/d/yy h:mm a Z");
68 Date date = fmt1.parse(
"6/29/2012 5:15 PM IST");
69 System.out.println(date);
71 DateFormat fmt2 =
new SimpleDateFormat(
"M/d/yy h:mm a");
72 fmt2.setTimeZone(TimeZone.getTimeZone(
"IST"));
73 System.out.println(fmt2.parse(
"6/29/2012 5:15 PM"));
75 DateFormat fmt3 =
new SimpleDateFormat(
"M/d/yy h:mm a");
76 fmt3.setTimeZone(TimeZone.getTimeZone(
"Asia/Kolkata"));
77 System.out.println(fmt3.parse(
"6/29/2012 5:15 PM"));