Source Code Cross Referenced for Date.java in  » 6.0-JDK-Modules » j2me » java » util » 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 » 6.0 JDK Modules » j2me » java.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *   
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:
027:        package java.util;
028:
029:        /**
030:         * The class Date represents a specific instant in time, with millisecond
031:         * precision.
032:         * <p>
033:         * This class has been subset for the J2ME based on the JDK 1.3 Date class.
034:         * Many methods and variables have been pruned, and other methods
035:         * simplified, in an effort to reduce the size of this class.
036:         * <p>
037:         * Although the Date class is intended to reflect coordinated universal
038:         * time (UTC), it may not do so exactly, depending on the host environment
039:         * of the Java Virtual Machine. Nearly all modern operating systems assume
040:         * that 1 day = 24x60x60 = 86400 seconds in all cases. In UTC, however,
041:         * about once every year or two there is an extra second, called a "leap
042:         * second." The leap second is always added as the last second of the
043:         * day, and always on December 31 or June 30. For example, the last minute
044:         * of the year 1995 was 61 seconds long, thanks to an added leap second.
045:         * Most computer clocks are not accurate enough to be able to reflect the
046:         * leap-second distinction.
047:         *
048:         * @see     java.util.TimeZone
049:         * @see     java.util.Calendar
050:         * @version CLDC 1.1 03/13/2002 (Based on JDK 1.3)
051:         */
052:
053:        public class Date {
054:
055:            /* If calendar is null, then fastTime indicates the time in millis.
056:             * Otherwise, fastTime is ignored, and calendar indicates the time.
057:             */
058:            private Calendar calendar;
059:            private long fastTime;
060:
061:            /**
062:             * Allocates a <code>Date</code> object and initializes it to
063:             * represent the current time specified number of milliseconds since the
064:             * standard base time known as "the epoch", namely January 1,
065:             * 1970, 00:00:00 GMT.
066:             * @see     java.lang.System#currentTimeMillis()
067:             */
068:            public Date() {
069:                this (System.currentTimeMillis());
070:            }
071:
072:            /**
073:             * Allocates a <code>Date</code> object and initializes it to
074:             * represent the specified number of milliseconds since the
075:             * standard base time known as "the epoch", namely January 1,
076:             * 1970, 00:00:00 GMT.
077:             *
078:             * @param   date   the milliseconds since January 1, 1970, 00:00:00 GMT.
079:             * @see     java.lang.System#currentTimeMillis()
080:             */
081:            public Date(long date) {
082:                calendar = Calendar.getInstance();
083:                if (calendar != null) {
084:                    calendar.setTimeInMillis(date);
085:                }
086:                fastTime = date;
087:            }
088:
089:            /**
090:             * Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
091:             * represented by this <tt>Date</tt> object.
092:             *
093:             * @return  the number of milliseconds since January 1, 1970, 00:00:00 GMT
094:             *          represented by this date.
095:             *
096:             * @see #setTime
097:             */
098:            public long getTime() {
099:                if (calendar != null) {
100:                    return calendar.getTimeInMillis();
101:                } else {
102:                    return fastTime;
103:                }
104:            }
105:
106:            /**
107:             * Sets this <tt>Date</tt> object to represent a point in time that is
108:             * <tt>time</tt> milliseconds after January 1, 1970 00:00:00 GMT.
109:             *
110:             * @param   time   the number of milliseconds.
111:             *
112:             * @see #getTime
113:             */
114:            public void setTime(long time) {
115:                if (calendar != null) {
116:                    calendar.setTimeInMillis(time);
117:                }
118:                fastTime = time;
119:            }
120:
121:            /**
122:             * Compares two dates for equality.
123:             * The result is <code>true</code> if and only if the argument is
124:             * not <code>null</code> and is a <code>Date</code> object that
125:             * represents the same point in time, to the millisecond, as this object.
126:             * <p>
127:             * Thus, two <code>Date</code> objects are equal if and only if the
128:             * <code>getTime</code> method returns the same <code>long</code>
129:             * value for both.
130:             *
131:             * @param   obj   the object to compare with.
132:             * @return  <code>true</code> if the objects are the same;
133:             *          <code>false</code> otherwise.
134:             * @see     java.util.Date#getTime()
135:             */
136:            public boolean equals(Object obj) {
137:                return obj != null && obj instanceof  Date
138:                        && getTime() == ((Date) obj).getTime();
139:            }
140:
141:            /**
142:             * Returns a hash code value for this object. The result is the
143:             * exclusive OR of the two halves of the primitive <tt>long</tt>
144:             * value returned by the {@link Date#getTime}
145:             * method. That is, the hash code is the value of the expression:
146:             * <blockquote><pre>
147:             * (int)(this.getTime()^(this.getTime() >>> 32))</pre></blockquote>
148:             *
149:             * @return  a hash code value for this object.
150:             */
151:            public int hashCode() {
152:                long ht = getTime();
153:                return (int) ht ^ (int) (ht >> 32);
154:            }
155:
156:            /**
157:             * Converts this <code>Date</code> object to a <code>String</code>
158:             * of the form:
159:             * <blockquote><pre>
160:             * dow mon dd hh:mm:ss zzz yyyy</pre></blockquote>
161:             * where:<ul>
162:             * <li><tt>dow</tt> is the day of the week (<tt>Sun, Mon, Tue, Wed,
163:             *     Thu, Fri, Sat</tt>).
164:             * <li><tt>mon</tt> is the month (<tt>Jan, Feb, Mar, Apr, May, Jun,
165:             *     Jul, Aug, Sep, Oct, Nov, Dec</tt>).
166:             * <li><tt>dd</tt> is the day of the month (<tt>01</tt> through
167:             *     <tt>31</tt>), as two decimal digits.
168:             * <li><tt>hh</tt> is the hour of the day (<tt>00</tt> through
169:             *     <tt>23</tt>), as two decimal digits.
170:             * <li><tt>mm</tt> is the minute within the hour (<tt>00</tt> through
171:             *     <tt>59</tt>), as two decimal digits.
172:             * <li><tt>ss</tt> is the second within the minute (<tt>00</tt> through
173:             *     <tt>61</tt>, as two decimal digits.
174:             * <li><tt>zzz</tt> is the time zone (and may reflect daylight savings
175:             *     time). If time zone information is not available, 
176:             *     then <tt>zzz</tt> is empty - that is, it consists
177:             *     of no characters at all.
178:             * <li><tt>yyyy</tt> is the year, as four decimal digits.
179:             * </ul>
180:             *
181:             * @return  a string representation of this date.
182:             * @since CLDC 1.1
183:             */
184:            public String toString() {
185:                return com.sun.cldc.util.j2me.CalendarImpl.toString(calendar);
186:            }
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.