1 // 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html#License 3 /* 4 ******************************************************************************* 5 * Copyright (C) 1996-2011, International Business Machines Corporation and * 6 * others. All Rights Reserved. * 7 ******************************************************************************* 8 * 9 */ 10 11 package com.ibm.icu.samples.util.timescale; 12 13 import java.util.Locale; 14 15 import com.ibm.icu.text.MessageFormat; 16 import com.ibm.icu.util.Calendar; 17 import com.ibm.icu.util.SimpleTimeZone; 18 import com.ibm.icu.util.TimeZone; 19 import com.ibm.icu.util.UniversalTimeScale; 20 21 /** 22 * This class demonstrates how to use <code>UniversalTimeScale</code> to 23 * convert from one local time scale to another. 24 * 25 * @see UniversalTimeScale 26 */ 27 public class PivotDemo { 28 29 /** 30 * The default constructor. 31 */ 32 public PivotDemo() 33 { 34 } 35 36 /** 37 * The <code>main()</code> method uses <code>UniversalTimeScale</code> to 38 * convert from the Java and Unix time scales to the ICU time scale. It uses 39 * a <code>Calendar</code> object to display the ICU time values. 40 * 41 * @param args the command line arguments. 42 */ 43 public static void main(String[] args) 44 { 45 TimeZone utc = new SimpleTimeZone(0, "UTC"); 46 Calendar cal = Calendar.getInstance(utc, Locale.ENGLISH); 47 MessageFormat fmt = new MessageFormat("{1} = {0, date, full} {0, time, full}"); 48 Object arguments[] = {cal, null}; 49 50 arguments[0] = cal; 51 52 System.out.println("\nJava test:"); 53 cal.setTimeInMillis(UniversalTimeScale.toLong(UniversalTimeScale.from(0, UniversalTimeScale.JAVA_TIME), UniversalTimeScale.ICU4C_TIME)); 54 arguments[1] = " 000000000000000"; 55 System.out.println(fmt.format(arguments)); 56 57 cal.setTimeInMillis(UniversalTimeScale.toLong(UniversalTimeScale.from(-62164684800000L, UniversalTimeScale.JAVA_TIME), UniversalTimeScale.ICU4C_TIME)); 58 arguments[1] = "-62164684800000L"; 59 System.out.println(fmt.format(arguments)); 60 61 cal.setTimeInMillis(UniversalTimeScale.toLong(UniversalTimeScale.from(-62135769600000L, UniversalTimeScale.JAVA_TIME), UniversalTimeScale.ICU4C_TIME)); 62 arguments[1] = "-62135769600000L"; 63 System.out.println(fmt.format(arguments)); 64 65 System.out.println("\nUnix test:"); 66 67 cal.setTimeInMillis(UniversalTimeScale.toLong(UniversalTimeScale.from(0x80000000, UniversalTimeScale.UNIX_TIME), UniversalTimeScale.ICU4C_TIME)); 68 arguments[1] = "0x80000000"; 69 System.out.println(fmt.format(arguments)); 70 71 cal.setTimeInMillis(UniversalTimeScale.toLong(UniversalTimeScale.from(0, UniversalTimeScale.UNIX_TIME), UniversalTimeScale.ICU4C_TIME)); 72 arguments[1] = "0x00000000"; 73 System.out.println(fmt.format(arguments)); 74 75 cal.setTimeInMillis(UniversalTimeScale.toLong(UniversalTimeScale.from(0x7FFFFFFF, UniversalTimeScale.UNIX_TIME), UniversalTimeScale.ICU4C_TIME)); 76 arguments[1] = "0x7FFFFFFF"; 77 System.out.println(fmt.format(arguments)); 78 79 } 80 } 81