Source Code Cross Referenced for EpochOffsets.java in  » Internationalization-Localization » icu4j » com » ibm » icu » dev » tool » timescale » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Internationalization Localization » icu4j » com.ibm.icu.dev.tool.timescale 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *******************************************************************************
003:         * Copyright (C) 2004-2006, International Business Machines Corporation and    *
004:         * others. All Rights Reserved.                                                *
005:         *******************************************************************************
006:         *
007:         */
008:
009:        package com.ibm.icu.dev.tool.timescale;
010:
011:        import java.util.Date;
012:        import java.util.Locale;
013:
014:        import com.ibm.icu.text.MessageFormat;
015:        import com.ibm.icu.util.Calendar;
016:        import com.ibm.icu.util.GregorianCalendar;
017:        import com.ibm.icu.util.SimpleTimeZone;
018:        import com.ibm.icu.util.TimeZone;
019:
020:        /**
021:         * This tool calculates the numeric values of the epoch offsets
022:         * used in UniversalTimeScale.
023:         * 
024:         * @see com.ibm.icu.util.UniversalTimeScale
025:         * 
026:         *@draft ICU 3.2 
027:         */
028:        public class EpochOffsets {
029:
030:            /**
031:             * The default constructor.
032:             * 
033:             * @draft ICU 3.2
034:             */
035:            public EpochOffsets() {
036:            }
037:
038:            private static final long ticks = 1;
039:            private static final long microseconds = ticks * 10;
040:            private static final long milliseconds = microseconds * 1000;
041:            private static final long seconds = milliseconds * 1000;
042:            private static final long minutes = seconds * 60;
043:            private static final long hours = minutes * 60;
044:            private static final long days = hours * 24;
045:            // Java measures time in milliseconds, not in 100ns ticks.
046:            private static final long javaDays = days / milliseconds;
047:
048:            private static int[][] epochDates = { { 1, Calendar.JANUARY, 1 },
049:                    { 1970, Calendar.JANUARY, 1 },
050:                    { 1601, Calendar.JANUARY, 1 },
051:                    { 1904, Calendar.JANUARY, 1 },
052:                    { 2001, Calendar.JANUARY, 1 },
053:                    { 1899, Calendar.DECEMBER, 31 },
054:                    { 1900, Calendar.MARCH, 1 } };
055:
056:            /**
057:             * The <code>main()</code> method calculates the epoch offsets used by the
058:             * <code>UniversalTimeScale</code> class.
059:             * 
060:             * The calculations are done using an ICU <code>Calendar</code> object. The first step is
061:             * to calculate the Universal Time Scale's epoch date. Then the epoch offsets are calculated
062:             * by calculating each epoch date, subtracting the universal epoch date from it, and converting
063:             * that value to ticks.
064:             * 
065:             * @param args - the command line arguments.
066:             * 
067:             * @draft ICU 3.2
068:             */
069:            public static void main(String[] args) {
070:                TimeZone utc = new SimpleTimeZone(0, "UTC");
071:
072:                // Jitterbug 5211: .Net System.DateTime uses the proleptic calendar,
073:                // while ICU by default uses the Julian calendar before 1582.
074:                // Original code: Calendar cal = Calendar.getInstance(utc, Locale.ENGLISH);
075:                // Use a proleptic Gregorian calendar for 0001AD and later by setting
076:                // the Gregorian change date before 0001AD with a value
077:                // that is safely before that date by any measure, i.e.,
078:                // more than 719164 days before 1970.
079:                long before0001AD = -1000000 * javaDays;
080:                GregorianCalendar cal = new GregorianCalendar(utc,
081:                        Locale.ENGLISH);
082:                cal.setGregorianChange(new Date(before0001AD));
083:
084:                MessageFormat fmt = new MessageFormat(
085:                        "{0, date, full} {0, time, full} = {1}");
086:                Object arguments[] = { cal, null };
087:
088:                System.out.println("Epoch offsets:");
089:
090:                // January 1, 0001 00:00:00 is the universal epoch date...
091:                cal.set(1, Calendar.JANUARY, 1, 0, 0, 0);
092:
093:                long universalEpoch = cal.getTimeInMillis();
094:
095:                for (int i = 0; i < epochDates.length; i += 1) {
096:                    int[] date = epochDates[i];
097:
098:                    cal.set(date[0], date[1], date[2]);
099:
100:                    long millis = cal.getTimeInMillis();
101:
102:                    arguments[1] = Long.toString((millis - universalEpoch)
103:                            * milliseconds);
104:
105:                    System.out.println(fmt.format(arguments));
106:                }
107:            }
108:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.