Re: NSTimestampFormatter question
Re: NSTimestampFormatter question
- Subject: Re: NSTimestampFormatter question
- From: Dom <email@hidden>
- Date: Thu, 26 Mar 2009 17:34:53 -0400
Ken, I think the exception is misleading as to the format possibly.
These lines:
java.lang.IllegalArgumentException: Invalid pattern yyyy'-'MM'-'dd'
'HH':'mm':'sszzzz
at com.webobjects.foundation.NSTimestampFormatter
$__NSSimpleDateFormat._zoneSubpatternRange(NSTimestampFormatter.java:
920)
at com.webobjects.foundation.NSTimestampFormatter
$__NSSimpleDateFormat._breakPattern(NSTimestampFormatter.java:853)
at
com
.webobjects
.foundation
.NSTimestampFormatter._parseDateFormat(NSTimestampFormatter.java:546)
at
com
.webobjects
.foundation.NSTimestampFormatter.parseObject(NSTimestampFormatter.java:
709)
at java.text.Format.parseObject(Format.java:219)
are making me think that NSTimestampFormatter is just invoking
SimpleDateFormat. But in answer to your question, yes, I'm sure I'm
using the % type formatting string and only that.
On Mar 26, 2009, at 4:23 PM, Chuck Hill wrote:
On Mar 26, 2009, at 1:05 PM, Dom wrote:
I know that this is deprecated in WO5.4, but I have a source
timestamp string that looks like this: 2009-03-26 15:56:50-0400
and I'm trying to create a formatter with the following pattern: %Y-
%m-%d %H:%M:%S%z
and I'm getting an Illegal arguement exception: Invalid pattern
yyyy'-'MM'-'dd' 'HH':'mm':'sszzzz when I try parsing the input
string into an NSTimestamp.
Try removing bits to isolate what it does not like.
Bingo; it doesn't like the timezone %z portion. So, if I parse the
input string to exclude those characters and modify the formatter
pattern string, it works. Unfortunately, I really need the timezone
info too, so read on below for that outcome
At first I tried just using the normal SimpleDateFormat class in
java, but apparently there's an issue with the "-" characters and
so I thought I'd revert to using NSTimestampFormatter to get past
this issue.
What is the issue with "-" characters? You should be able to escape
them, no?
I found a thread indicating that you have to literally replace them;
misplaced the url, but googling "SimpleDateFormat with literal
characters" (or something like that) turned up an article on Sun's
site about it. More annoying is that Sun's documentation specifically
refers to format strings containing the dash character;-)
Am I doing something wrong? OK, dumb question. What am I doing
wrong? ;-)
Not sure yet. I do recall that NSTimestampFormatter and time zone
parsing or formatting is somehow buggy.
Uh, yeah. I'd have to agree here. And I think it's more due to it's
reliance on SimpleDateFormat possibly.
Anyway, by inserting a space between the seconds and timezone portions
of the pattern string, and wrangling the input string same, it works.
Geesh...;-)
Thanks guys; really appreciate the prompt replies and help.
Dom
Chuck
--
Chuck Hill Senior Consultant / VP Development
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden