|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
[OT] Parsing xs:dateTime values-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1 All, I posted this on the commons-user mailing list, but I'm not getting any love. I'm cross-posting to see if anyone on this list might have any good ideas. | Hi, I'm looking for an implementation of a String->Date converter for | xs:dateTime, which has an odd format. It's not directly supportable by | java.text.SimpleDateFormat and looks like a regular expression is the | only way to go. | | Does anyone have an implementation they'd care to share, or any tips in | particular? I'd be glad to share whatever I come up with if there isn't | anything already out there. My existing implementation uses regular expressions, which seems a bit overkill. Thanks, - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkgsXdIACgkQ9CaO5/Lv0PAZawCffPNDLZ3bXczy89Cm1ptDzu1E va4AnRjfICMeUROWQGI40ts3CwZXtEOB =dDWw -----END PGP SIGNATURE----- --------------------------------------------------------------------- To start a new topic, e-mail: users@... To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: [OT] Parsing xs:dateTime valuesHi,
You don't need regexp. Do you mean something like: private static final String ISO8601_DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss"; private static final java.text.SimpleDateFormat ISO8601 = new java.text.SimpleDateFormat( ISO8601_DATEFORMAT, java.util.Locale.US); public static final Date getDateFromIso8601(final String iso8601) throws ParseException { return ISO8601.parse(iso8601); } best, -Rob On Thu, 2008-05-15 at 12:00 -0400, Christopher Schultz wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > All, > > I posted this on the commons-user mailing list, but I'm not getting any > love. I'm cross-posting to see if anyone on this list might have any > good ideas. > > | Hi, I'm looking for an implementation of a String->Date converter for > | xs:dateTime, which has an odd format. It's not directly supportable by > | java.text.SimpleDateFormat and looks like a regular expression is the > | only way to go. > | > | Does anyone have an implementation they'd care to share, or any tips in > | particular? I'd be glad to share whatever I come up with if there isn't > | anything already out there. > > My existing implementation uses regular expressions, which seems a bit > overkill. > > Thanks, > - -chris > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.9 (MingW32) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > > iEYEARECAAYFAkgsXdIACgkQ9CaO5/Lv0PAZawCffPNDLZ3bXczy89Cm1ptDzu1E > va4AnRjfICMeUROWQGI40ts3CwZXtEOB > =dDWw > -----END PGP SIGNATURE----- > > --------------------------------------------------------------------- > To start a new topic, e-mail: users@... > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... > --------------------------------------------------------------------- To start a new topic, e-mail: users@... To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: [OT] Parsing xs:dateTime valuesOne cautionary observation about the use of shared SimpleDateFormat
instances: they are not threadsafe. While it seems like a good idea to create these for various formats and hold them as class static or instance members, you need to do something to prevent threading issues. I have run into problems using SimpleDateFormat in this way in a multiprocessor environment, which lead to using the following simple subclass instead: public class SynchronizedSimpleDateFormat extends SimpleDateFormat { public SynchronizedSimpleDateFormat() { super(); } public SynchronizedSimpleDateFormat(String arg0) { super(arg0); } public SynchronizedSimpleDateFormat(String arg0, DateFormatSymbols arg1) { super(arg0, arg1); } public SynchronizedSimpleDateFormat(String arg0, Locale arg1) { super(arg0, arg1); } // Note that we only need to synchronize this format method, as the others all use this one internally public synchronized StringBuffer format(Date arg0, StringBuffer arg1, FieldPosition arg2) { return super.format(arg0, arg1, arg2); } public synchronized Date parse(String arg0, ParsePosition arg1) { return super.parse(arg0, arg1); } public synchronized Date parse(String arg0) throws ParseException { return super.parse(arg0); } } Please respond to "Tomcat Users List" <users@...> To: Tomcat Users List <users@...> cc: Subject: Re: [OT] Parsing xs:dateTime values Hi, You don't need regexp. Do you mean something like: private static final String ISO8601_DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss"; private static final java.text.SimpleDateFormat ISO8601 = new java.text.SimpleDateFormat( ISO8601_DATEFORMAT, java.util.Locale.US); public static final Date getDateFromIso8601(final String iso8601) throws ParseException { return ISO8601.parse(iso8601); } best, -Rob On Thu, 2008-05-15 at 12:00 -0400, Christopher Schultz wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > All, > > I posted this on the commons-user mailing list, but I'm not getting any > love. I'm cross-posting to see if anyone on this list might have any > good ideas. > > | Hi, I'm looking for an implementation of a String->Date converter for > | xs:dateTime, which has an odd format. It's not directly supportable by > | java.text.SimpleDateFormat and looks like a regular expression is the > | only way to go. > | > | Does anyone have an implementation they'd care to share, or any tips > | particular? I'd be glad to share whatever I come up with if there isn't > | anything already out there. > > My existing implementation uses regular expressions, which seems a bit > overkill. > > Thanks, > - -chris > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.9 (MingW32) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > > iEYEARECAAYFAkgsXdIACgkQ9CaO5/Lv0PAZawCffPNDLZ3bXczy89Cm1ptDzu1E > va4AnRjfICMeUROWQGI40ts3CwZXtEOB > =dDWw > -----END PGP SIGNATURE----- > > --------------------------------------------------------------------- > To start a new topic, e-mail: users@... > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... > --------------------------------------------------------------------- To start a new topic, e-mail: users@... To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: [OT] Parsing xs:dateTime values-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1 Robert, Robert Koberg wrote: | You don't need regexp. Do you mean something like: | | private static final String ISO8601_DATEFORMAT = | "yyyy-MM-dd'T'HH:mm:ss"; This does not account for the milliseconds and timezone. The TX format for xs:dateTime does not match anything that SimpleDateFormat will read, and the fact that the ".SSS" (in simpleDateFormat-speak) is completely optional also fouls things up. :( - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkgsZk8ACgkQ9CaO5/Lv0PBOHwCgnBGARxu4fVS5LGP9c4JAMjYk rEAAnR0VbwIADqE5LQ68jyco8EBzggq8 =OOkX -----END PGP SIGNATURE----- --------------------------------------------------------------------- To start a new topic, e-mail: users@... To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: [OT] Parsing xs:dateTime values-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1 DJohnson, DJohnson@... wrote: | I have run into problems using SimpleDateFormat in this way in a | multiprocessor environment, which lead to using the following simple | subclass instead: IMO it's better just to create DateFormat objects on the fly and discard them. No synchronization or additional classes required. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkgsZqAACgkQ9CaO5/Lv0PD0GACgm0rthSNUqXl8ZsS/1p82+F/I o6wAoLDt4RDIounMT1ZSsDC74Tu9b0Oy =EXBq -----END PGP SIGNATURE----- --------------------------------------------------------------------- To start a new topic, e-mail: users@... To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: [OT] Parsing xs:dateTime valueswhoops and thanks :)
On Thu, 2008-05-15 at 12:27 -0400, DJohnson@... wrote: > One cautionary observation about the use of shared SimpleDateFormat > instances: they are not threadsafe. > While it seems like a good idea to create these for various formats and > hold them as class static or instance members, you need to do something to > prevent threading issues. > I have run into problems using SimpleDateFormat in this way in a > multiprocessor environment, which lead to using the following simple > subclass instead: > > public class SynchronizedSimpleDateFormat extends SimpleDateFormat { > > public SynchronizedSimpleDateFormat() { > super(); > } > > public SynchronizedSimpleDateFormat(String arg0) { > super(arg0); > } > > public SynchronizedSimpleDateFormat(String arg0, DateFormatSymbols arg1) > { > super(arg0, arg1); > } > > public SynchronizedSimpleDateFormat(String arg0, Locale arg1) { > super(arg0, arg1); > } > > // Note that we only need to synchronize this format method, as the > others all use this one internally > public synchronized StringBuffer format(Date arg0, StringBuffer arg1, > FieldPosition arg2) { > return super.format(arg0, arg1, arg2); > } > > public synchronized Date parse(String arg0, ParsePosition arg1) { > return super.parse(arg0, arg1); > } > > public synchronized Date parse(String arg0) throws ParseException { > return super.parse(arg0); > } > > } > > > > Please respond to "Tomcat Users List" <users@...> > > To: Tomcat Users List <users@...> > cc: > Subject: Re: [OT] Parsing xs:dateTime values > > > Hi, > > You don't need regexp. Do you mean something like: > > private static final String ISO8601_DATEFORMAT = > "yyyy-MM-dd'T'HH:mm:ss"; > > private static final java.text.SimpleDateFormat ISO8601 = new > java.text.SimpleDateFormat( > ISO8601_DATEFORMAT, java.util.Locale.US); > > > public static final Date getDateFromIso8601(final String iso8601) > throws ParseException { > return ISO8601.parse(iso8601); > } > > best, > -Rob > > > On Thu, 2008-05-15 at 12:00 -0400, Christopher Schultz wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA1 > > > > All, > > > > I posted this on the commons-user mailing list, but I'm not getting any > > love. I'm cross-posting to see if anyone on this list might have any > > good ideas. > > > > | Hi, I'm looking for an implementation of a String->Date converter for > > | xs:dateTime, which has an odd format. It's not directly supportable by > > | java.text.SimpleDateFormat and looks like a regular expression is the > > | only way to go. > > | > > | Does anyone have an implementation they'd care to share, or any tips > in > > | particular? I'd be glad to share whatever I come up with if there > isn't > > | anything already out there. > > > > My existing implementation uses regular expressions, which seems a bit > > overkill. > > > > Thanks, > > - -chris > > -----BEGIN PGP SIGNATURE----- > > Version: GnuPG v1.4.9 (MingW32) > > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > > > > iEYEARECAAYFAkgsXdIACgkQ9CaO5/Lv0PAZawCffPNDLZ3bXczy89Cm1ptDzu1E > > va4AnRjfICMeUROWQGI40ts3CwZXtEOB > > =dDWw > > -----END PGP SIGNATURE----- > > > > --------------------------------------------------------------------- > > To start a new topic, e-mail: users@... > > To unsubscribe, e-mail: users-unsubscribe@... > > For additional commands, e-mail: users-help@... > > > > > --------------------------------------------------------------------- > To start a new topic, e-mail: users@... > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... > > > --------------------------------------------------------------------- To start a new topic, e-mail: users@... To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
| Free Forum Powered by Nabble | Forum Help |