2 *******************************************************************************
3 * Copyright (C) 1996-2008, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
9 package com.ibm.icu.dev.demo.timescale;
11 import java.util.Locale;
13 import com.ibm.icu.text.MessageFormat;
14 import com.ibm.icu.util.Calendar;
15 import com.ibm.icu.util.SimpleTimeZone;
16 import com.ibm.icu.util.TimeZone;
17 import com.ibm.icu.util.UniversalTimeScale;
20 * This class demonstrates how to use <code>UniversalTimeScale</code> to
21 * convert from one local time scale to another.
23 * @see UniversalTimeScale
25 public class PivotDemo {
28 * The default constructor.
35 * The <code>main()</code> method uses <code>UniversalTimeScale</code> to
36 * convert from the Java and Unix time scales to the ICU time scale. It uses
37 * a <code>Calendar</code> object to display the ICU time values.
39 * @param args the command line arguments.
41 public static void main(String[] args)
43 TimeZone utc = new SimpleTimeZone(0, "UTC");
44 Calendar cal = Calendar.getInstance(utc, Locale.ENGLISH);
45 MessageFormat fmt = new MessageFormat("{1} = {0, date, full} {0, time, full}");
46 Object arguments[] = {cal, null};
50 System.out.println("\nJava test:");
51 cal.setTimeInMillis(UniversalTimeScale.toLong(UniversalTimeScale.from(0, UniversalTimeScale.JAVA_TIME), UniversalTimeScale.ICU4C_TIME));
52 arguments[1] = " 000000000000000";
53 System.out.println(fmt.format(arguments));
55 cal.setTimeInMillis(UniversalTimeScale.toLong(UniversalTimeScale.from(-62164684800000L, UniversalTimeScale.JAVA_TIME), UniversalTimeScale.ICU4C_TIME));
56 arguments[1] = "-62164684800000L";
57 System.out.println(fmt.format(arguments));
59 cal.setTimeInMillis(UniversalTimeScale.toLong(UniversalTimeScale.from(-62135769600000L, UniversalTimeScale.JAVA_TIME), UniversalTimeScale.ICU4C_TIME));
60 arguments[1] = "-62135769600000L";
61 System.out.println(fmt.format(arguments));
63 System.out.println("\nUnix test:");
65 cal.setTimeInMillis(UniversalTimeScale.toLong(UniversalTimeScale.from(0x80000000, UniversalTimeScale.UNIX_TIME), UniversalTimeScale.ICU4C_TIME));
66 arguments[1] = "0x80000000";
67 System.out.println(fmt.format(arguments));
69 cal.setTimeInMillis(UniversalTimeScale.toLong(UniversalTimeScale.from(0, UniversalTimeScale.UNIX_TIME), UniversalTimeScale.ICU4C_TIME));
70 arguments[1] = "0x00000000";
71 System.out.println(fmt.format(arguments));
73 cal.setTimeInMillis(UniversalTimeScale.toLong(UniversalTimeScale.from(0x7FFFFFFF, UniversalTimeScale.UNIX_TIME), UniversalTimeScale.ICU4C_TIME));
74 arguments[1] = "0x7FFFFFFF";
75 System.out.println(fmt.format(arguments));