Source Code Cross Referenced for Examples.java in  » Development » Joda-Time » org » joda » example » time » 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 » Development » Joda Time » org.joda.example.time 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright 2001-2005 Stephen Colebourne
003:         *
004:         *  Licensed under the Apache License, Version 2.0 (the "License");
005:         *  you may not use this file except in compliance with the License.
006:         *  You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         *  Unless required by applicable law or agreed to in writing, software
011:         *  distributed under the License is distributed on an "AS IS" BASIS,
012:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         *  See the License for the specific language governing permissions and
014:         *  limitations under the License.
015:         */
016:        package org.joda.example.time;
017:
018:        import java.util.Locale;
019:
020:        import org.joda.time.DateTime;
021:        import org.joda.time.Instant;
022:
023:        /**
024:         * Example code demonstrating how to use Joda-Time.
025:         *
026:         * @author Stephen Colebourne
027:         */
028:        public class Examples {
029:
030:            public static void main(String[] args) throws Exception {
031:                try {
032:                    new Examples().run();
033:                } catch (Throwable ex) {
034:                    ex.printStackTrace();
035:                }
036:            }
037:
038:            private void run() {
039:                runInstant();
040:                System.out.println();
041:                runDateTime();
042:                System.out.println();
043:            }
044:
045:            private void runInstant() {
046:                System.out.println("Instant");
047:                System.out.println("=======");
048:                System.out
049:                        .println("Instant stores a point in the datetime continuum as millisecs from 1970-01-01T00:00:00Z");
050:                System.out.println("Instant is immutable and thread-safe");
051:                System.out.println("                      in = new Instant()");
052:                Instant in = new Instant();
053:                System.out
054:                        .println("Millisecond time:     in.getMillis():           "
055:                                + in.getMillis());
056:                System.out
057:                        .println("ISO string version:   in.toString():            "
058:                                + in.toString());
059:                System.out
060:                        .println("ISO chronology:       in.getChronology():       "
061:                                + in.getChronology());
062:                System.out
063:                        .println("UTC time zone:        in.getDateTimeZone():     "
064:                                + in.getZone());
065:                System.out
066:                        .println("Change millis:        in.withMillis(0):         "
067:                                + in.withMillis(0L));
068:                System.out.println("");
069:                System.out
070:                        .println("Convert to Instant:   in.toInstant():           "
071:                                + in.toInstant());
072:                System.out
073:                        .println("Convert to DateTime:  in.toDateTime():          "
074:                                + in.toDateTime());
075:                System.out
076:                        .println("Convert to MutableDT: in.toMutableDateTime():   "
077:                                + in.toMutableDateTime());
078:                System.out
079:                        .println("Convert to Date:      in.toDate():              "
080:                                + in.toDate());
081:                System.out.println("");
082:                System.out
083:                        .println("                      in2 = new Instant(in.getMillis() + 10)");
084:                Instant in2 = new Instant(in.getMillis() + 10);
085:                System.out
086:                        .println("Equals ms and chrono: in.equals(in2):           "
087:                                + in.equals(in2));
088:                System.out
089:                        .println("Compare millisecond:  in.compareTo(in2):        "
090:                                + in.compareTo(in2));
091:                System.out
092:                        .println("Compare millisecond:  in.isEqual(in2):          "
093:                                + in.isEqual(in2));
094:                System.out
095:                        .println("Compare millisecond:  in.isAfter(in2):          "
096:                                + in.isAfter(in2));
097:                System.out
098:                        .println("Compare millisecond:  in.isBefore(in2):         "
099:                                + in.isBefore(in2));
100:            }
101:
102:            private void runDateTime() {
103:                System.out.println("DateTime");
104:                System.out.println("=======");
105:                System.out
106:                        .println("DateTime stores a the date and time using millisecs from 1970-01-01T00:00:00Z internally");
107:                System.out.println("DateTime is immutable and thread-safe");
108:                System.out.println("                      in = new DateTime()");
109:                DateTime in = new DateTime();
110:                System.out
111:                        .println("Millisecond time:     in.getMillis():           "
112:                                + in.getMillis());
113:                System.out
114:                        .println("ISO string version:   in.toString():            "
115:                                + in.toString());
116:                System.out
117:                        .println("ISO chronology:       in.getChronology():       "
118:                                + in.getChronology());
119:                System.out
120:                        .println("Your time zone:       in.getDateTimeZone():     "
121:                                + in.getZone());
122:                System.out
123:                        .println("Change millis:        in.withMillis(0):         "
124:                                + in.withMillis(0L));
125:                System.out.println("");
126:                System.out
127:                        .println("Get year:             in.getYear():             "
128:                                + in.getYear());
129:                System.out
130:                        .println("Get monthOfYear:      in.getMonthOfYear():      "
131:                                + in.getMonthOfYear());
132:                System.out
133:                        .println("Get dayOfMonth:       in.getDayOfMonth():       "
134:                                + in.getDayOfMonth());
135:                System.out.println("...");
136:                System.out
137:                        .println("Property access:      in.dayOfWeek().get():                   "
138:                                + in.dayOfWeek().get());
139:                System.out
140:                        .println("Day of week as text:  in.dayOfWeek().getAsText():             "
141:                                + in.dayOfWeek().getAsText());
142:                System.out
143:                        .println("Day as short text:    in.dayOfWeek().getAsShortText():        "
144:                                + in.dayOfWeek().getAsShortText());
145:                System.out
146:                        .println("Day in french:        in.dayOfWeek().getAsText(Locale.FRENCH):"
147:                                + in.dayOfWeek().getAsText(Locale.FRENCH));
148:                System.out
149:                        .println("Max allowed value:    in.dayOfWeek().getMaximumValue():       "
150:                                + in.dayOfWeek().getMaximumValue());
151:                System.out
152:                        .println("Min allowed value:    in.dayOfWeek().getMinimumValue():       "
153:                                + in.dayOfWeek().getMinimumValue());
154:                System.out
155:                        .println("Copy & set to Jan:    in.monthOfYear().setCopy(1):            "
156:                                + in.monthOfYear().setCopy(1));
157:                System.out
158:                        .println("Copy & add 14 months: in.monthOfYear().addCopy(14):           "
159:                                + in.monthOfYear().addToCopy(14));
160:                System.out
161:                        .println("Add 14 mnths in field:in.monthOfYear().addWrapFieldCopy(14):  "
162:                                + in.monthOfYear().addWrapFieldToCopy(14));
163:                System.out.println("...");
164:                System.out
165:                        .println("Convert to Instant:   in.toInstant():           "
166:                                + in.toInstant());
167:                System.out
168:                        .println("Convert to DateTime:  in.toDateTime():          "
169:                                + in.toDateTime());
170:                System.out
171:                        .println("Convert to MutableDT: in.toMutableDateTime():   "
172:                                + in.toMutableDateTime());
173:                System.out
174:                        .println("Convert to Date:      in.toDate():              "
175:                                + in.toDate());
176:                System.out
177:                        .println("Convert to Calendar:  in.toCalendar(Locale.UK): "
178:                                + in.toCalendar(Locale.UK).toString()
179:                                        .substring(0, 46));
180:                System.out
181:                        .println("Convert to GregCal:   in.toGregorianCalendar(): "
182:                                + in.toGregorianCalendar().toString()
183:                                        .substring(0, 46));
184:                System.out.println("");
185:                System.out
186:                        .println("                      in2 = new DateTime(in.getMillis() + 10)");
187:                DateTime in2 = new DateTime(in.getMillis() + 10);
188:                System.out
189:                        .println("Equals ms and chrono: in.equals(in2):           "
190:                                + in.equals(in2));
191:                System.out
192:                        .println("Compare millisecond:  in.compareTo(in2):        "
193:                                + in.compareTo(in2));
194:                System.out
195:                        .println("Compare millisecond:  in.isEqual(in2):          "
196:                                + in.isEqual(in2));
197:                System.out
198:                        .println("Compare millisecond:  in.isAfter(in2):          "
199:                                + in.isAfter(in2));
200:                System.out
201:                        .println("Compare millisecond:  in.isBefore(in2):         "
202:                                + in.isBefore(in2));
203:            }
204:
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.