• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTimestampFormatter question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTimestampFormatter question


  • Subject: Re: NSTimestampFormatter question
  • From: Chuck Hill <email@hidden>
  • Date: Thu, 26 Mar 2009 16:00:12 -0700


On Mar 26, 2009, at 2:34 PM, Dom wrote:

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

If you want the time zone rendered as -0400, should those those not be capital Z?


Z	Time zone	RFC 822 time zone	-0800

I use a format like this:
HTTPServiceTimestampFormat = "yyyy-MM-dd HH:mm:ss Z"; // Note java.text.SimpleDateFormat Symbols!!!




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

I am pretty sure that is a know, reported bug. And part of the reason this class is deprecated.



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;-)

Do you have a link to that?




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
References: 
 >NSTimestampFormatter question (From: Dom <email@hidden>)
 >Re: NSTimestampFormatter question (From: Chuck Hill <email@hidden>)
 >Re: NSTimestampFormatter question (From: Dom <email@hidden>)

  • Prev by Date: Re: newEO.localInstanceIn(localEditingContext)
  • Next by Date: Re: newEO.localInstanceIn(localEditingContext)
  • Previous by thread: Re: NSTimestampFormatter question
  • Next by thread: Re: NSTimestampFormatter question
  • Index(es):
    • Date
    • Thread