]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_8_1_1/demos/src/com/ibm/icu/dev/demo/timescale/PivotDemo.java
Added flags.
[Dictionary.git] / jars / icu4j-4_8_1_1 / demos / src / com / ibm / icu / dev / demo / timescale / PivotDemo.java
1 /*
2  *******************************************************************************
3  * Copyright (C) 1996-2008, International Business Machines Corporation and    *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  *
7  */
8
9 package com.ibm.icu.dev.demo.timescale;
10
11 import java.util.Locale;
12
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;
18
19 /**
20  * This class demonstrates how to use <code>UniversalTimeScale</code> to
21  * convert from one local time scale to another.
22  * 
23  * @see UniversalTimeScale
24  */
25 public class PivotDemo {
26
27     /**
28      * The default constructor.
29      */
30     public PivotDemo()
31     {
32     }
33
34     /**
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.
38      * 
39      * @param args the command line arguments.
40      */
41     public static void main(String[] args)
42     {
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};
47         
48         arguments[0] = cal;
49         
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));
54         
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));
58         
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));
62         
63         System.out.println("\nUnix test:");
64         
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));
68         
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));
72         
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));
76         
77     }
78 }