001: /*
002: *******************************************************************************
003: * Copyright (C) 1996-2004, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: *
007: */
008:
009: package com.ibm.icu.dev.demo.timescale;
010:
011: import java.util.Locale;
012:
013: import com.ibm.icu.text.MessageFormat;
014: import com.ibm.icu.util.Calendar;
015: import com.ibm.icu.util.SimpleTimeZone;
016: import com.ibm.icu.util.TimeZone;
017: import com.ibm.icu.util.UniversalTimeScale;
018:
019: /**
020: * This class demonstrates how to use <code>UniversalTimeScale</code> to
021: * convert from one local time scale to another.
022: *
023: * @see UniversalTimeScale
024: *
025: * @draft ICU 3.2
026: */
027: public class PivotDemo {
028:
029: /**
030: * The default constructor.
031: *
032: * @draft ICU 3.2
033: */
034: public PivotDemo() {
035: }
036:
037: /**
038: * The <code>main()</code> method uses <code>UniversalTimeScale</code> to
039: * convert from the Java and Unix time scales to the ICU time scale. It uses
040: * a <code>Calendar</code> object to display the ICU time values.
041: *
042: * @param args the command line arguments.
043: *
044: * @draft ICU 3.2
045: */
046: public static void main(String[] args) {
047: TimeZone utc = new SimpleTimeZone(0, "UTC");
048: Calendar cal = Calendar.getInstance(utc, Locale.ENGLISH);
049: MessageFormat fmt = new MessageFormat(
050: "{1} = {0, date, full} {0, time, full}");
051: Object arguments[] = { cal, null };
052:
053: arguments[0] = cal;
054:
055: System.out.println("\nJava test:");
056: cal.setTimeInMillis(UniversalTimeScale.toLong(
057: UniversalTimeScale
058: .from(0, UniversalTimeScale.JAVA_TIME),
059: UniversalTimeScale.ICU4C_TIME));
060: arguments[1] = " 000000000000000";
061: System.out.println(fmt.format(arguments));
062:
063: cal.setTimeInMillis(UniversalTimeScale.toLong(
064: UniversalTimeScale.from(-62164684800000L,
065: UniversalTimeScale.JAVA_TIME),
066: UniversalTimeScale.ICU4C_TIME));
067: arguments[1] = "-62164684800000L";
068: System.out.println(fmt.format(arguments));
069:
070: cal.setTimeInMillis(UniversalTimeScale.toLong(
071: UniversalTimeScale.from(-62135769600000L,
072: UniversalTimeScale.JAVA_TIME),
073: UniversalTimeScale.ICU4C_TIME));
074: arguments[1] = "-62135769600000L";
075: System.out.println(fmt.format(arguments));
076:
077: System.out.println("\nUnix test:");
078:
079: cal.setTimeInMillis(UniversalTimeScale.toLong(
080: UniversalTimeScale.from(0x80000000,
081: UniversalTimeScale.UNIX_TIME),
082: UniversalTimeScale.ICU4C_TIME));
083: arguments[1] = "0x80000000";
084: System.out.println(fmt.format(arguments));
085:
086: cal.setTimeInMillis(UniversalTimeScale.toLong(
087: UniversalTimeScale
088: .from(0, UniversalTimeScale.UNIX_TIME),
089: UniversalTimeScale.ICU4C_TIME));
090: arguments[1] = "0x00000000";
091: System.out.println(fmt.format(arguments));
092:
093: cal.setTimeInMillis(UniversalTimeScale.toLong(
094: UniversalTimeScale.from(0x7FFFFFFF,
095: UniversalTimeScale.UNIX_TIME),
096: UniversalTimeScale.ICU4C_TIME));
097: arguments[1] = "0x7FFFFFFF";
098: System.out.println(fmt.format(arguments));
099:
100: }
101: }
|