1 16 package org.apache.roller.util; 17 18 import java.text.SimpleDateFormat ; 19 import java.util.Date ; 20 import java.util.TimeZone ; 21 22 29 public class ISO8601DateParser { 30 31 34 47 52 66 68 public static Date parse( String input ) throws java.text.ParseException { 77 78 SimpleDateFormat df = new SimpleDateFormat ( "yyyy-MM-dd'T'HH:mm:ssz" ); 81 82 if ( input.endsWith( "Z" ) ) { 84 input = input.substring( 0, input.length() - 1) + "GMT-00:00"; 85 } else { 86 int inset = 6; 87 88 String s0 = input.substring( 0, input.length() - inset ); 89 String s1 = input.substring( input.length() - inset, input.length() ); 90 91 input = s0 + "GMT" + s1; 92 } 93 94 return df.parse( input ); 95 96 } 97 98 public static String toString( Date date ) { 99 100 SimpleDateFormat df = new SimpleDateFormat ( "yyyy-MM-dd'T'HH:mm:ssz" ); 101 102 TimeZone tz = TimeZone.getTimeZone( "UTC" ); 103 104 df.setTimeZone( tz ); 105 106 String output = df.format( date ); 107 108 int inset0 = 9; 109 int inset1 = 6; 110 111 String s0 = output.substring( 0, output.length() - inset0 ); 112 String s1 = output.substring( output.length() - inset1, output.length() ); 113 114 String result = s0 + s1; 115 116 result = result.replaceAll( "UTC", "+00:00" ); 117 118 return result; 119 120 } 121 122 } | Popular Tags |