1 16 package org.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 private static SimpleDateFormat df 35 = new SimpleDateFormat ( "yyyy-MM-dd'T'HH:mm:ssz" ); 36 37 50 55 69 71 public static Date parse( String input ) throws java.text.ParseException { 80 81 84 if ( input.endsWith( "Z" ) ) { 86 input = input.substring( 0, input.length() - 1) + "GMT-00:00"; 87 } else { 88 int inset = 6; 89 90 String s0 = input.substring( 0, input.length() - inset ); 91 String s1 = input.substring( input.length() - inset, input.length() ); 92 93 input = s0 + "GMT" + s1; 94 } 95 96 return df.parse( input ); 97 98 } 99 100 public static String toString( Date date ) { 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 |