Source Code Cross Referenced for ISO8601DateParser.java in  » Portal » stringbeans-3.5 » com » nabhinc » 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 » Portal » stringbeans 3.5 » com.nabhinc.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1999,2004 The Apache Software Foundation.
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:         * Modified by Nabh Information Systems, Inc. for Stringbeans/Juggets usage.
017:         */
018:        package com.nabhinc.util;
019:
020:        import java.text.SimpleDateFormat;
021:        import java.util.Date;
022:        import java.util.TimeZone;
023:
024:        /**
025:         * ISO 8601 date parsing utility.  Designed for parsing the ISO subset used in
026:         * Dublin Core, RSS 1.0, and Atom.
027:         * 
028:         * @author <a href="mailto:burton@apache.org">Kevin A. Burton (burtonator)</a>
029:         * @version $Id: ISO8601DateParser.java,v 1.2 2005/06/03 20:25:29 snoopdave Exp $
030:         */
031:        public class ISO8601DateParser {
032:
033:            // 2004-06-14T19:GMT20:30Z
034:            // 2004-06-20T06:GMT22:01Z
035:
036:            // http://www.cl.cam.ac.uk/~mgk25/iso-time.html
037:            //    
038:            // http://www.intertwingly.net/wiki/pie/DateTime
039:            //
040:            // http://www.w3.org/TR/NOTE-datetime
041:            //
042:            // Different standards may need different levels of granularity in the date and
043:            // time, so this profile defines six levels. Standards that reference this
044:            // profile should specify one or more of these granularities. If a given
045:            // standard allows more than one granularity, it should specify the meaning of
046:            // the dates and times with reduced precision, for example, the result of
047:            // comparing two dates with different precisions.
048:
049:            // The formats are as follows. Exactly the components shown here must be
050:            // present, with exactly this punctuation. Note that the "T" appears literally
051:            // in the string, to indicate the beginning of the time element, as specified in
052:            // ISO 8601.
053:
054:            //    Year:
055:            //       YYYY (eg 1997)
056:            //    Year and month:
057:            //       YYYY-MM (eg 1997-07)
058:            //    Complete date:
059:            //       YYYY-MM-DD (eg 1997-07-16)
060:            //    Complete date plus hours and minutes:
061:            //       YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
062:            //    Complete date plus hours, minutes and seconds:
063:            //       YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
064:            //    Complete date plus hours, minutes, seconds and a decimal fraction of a
065:            // second
066:            //       YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
067:
068:            // where:
069:
070:            //      YYYY = four-digit year
071:            //      MM   = two-digit month (01=January, etc.)
072:            //      DD   = two-digit day of month (01 through 31)
073:            //      hh   = two digits of hour (00 through 23) (am/pm NOT allowed)
074:            //      mm   = two digits of minute (00 through 59)
075:            //      ss   = two digits of second (00 through 59)
076:            //      s    = one or more digits representing a decimal fraction of a second
077:            //      TZD  = time zone designator (Z or +hh:mm or -hh:mm)
078:            public static Date parse(String input)
079:                    throws java.text.ParseException {
080:
081:                //NOTE: SimpleDateFormat uses GMT[-+]hh:mm for the TZ which breaks
082:                //things a bit.  Before we go on we have to repair this.
083:                SimpleDateFormat df = new SimpleDateFormat(
084:                        "yyyy-MM-dd'T'HH:mm:ssz");
085:
086:                //this is zero time so we need to add that TZ indicator for 
087:                if (input.endsWith("Z")) {
088:                    input = input.substring(0, input.length() - 1)
089:                            + "GMT-00:00";
090:                } else {
091:                    int inset = 6;
092:
093:                    String s0 = input.substring(0, input.length() - inset);
094:                    String s1 = input.substring(input.length() - inset, input
095:                            .length());
096:
097:                    input = s0 + "GMT" + s1;
098:                }
099:
100:                return df.parse(input);
101:
102:            }
103:
104:            public static String toString(Date date) {
105:
106:                SimpleDateFormat df = new SimpleDateFormat(
107:                        "yyyy-MM-dd'T'HH:mm:ssz");
108:
109:                TimeZone tz = TimeZone.getTimeZone("UTC");
110:
111:                df.setTimeZone(tz);
112:
113:                String output = df.format(date);
114:
115:                int inset0 = 9;
116:                int inset1 = 6;
117:
118:                String s0 = output.substring(0, output.length() - inset0);
119:                String s1 = output.substring(output.length() - inset1, output
120:                        .length());
121:
122:                String result = s0 + s1;
123:
124:                result = result.replaceAll("UTC", "+00:00");
125:
126:                return result;
127:
128:            }
129:
130:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.