Re: NSDate with Format?
Re: NSDate with Format?
- Subject: Re: NSDate with Format?
- From: Pierce Freeman <email@hidden>
- Date: Fri, 03 Apr 2009 15:20:57 -0700
- Thread-topic: NSDate with Format?
--
NSDateFormatter is your friend. =)
You use it like this:
NSDateFormatter * f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"YYYY-mm-dd"];
NSLog([f stringFromDate:aDate]);
[f release];
There's also a really handy "dateFromString" method that will parse a
string according to the format string you specify.
This page has lots of good info on what the formatting specifiers are:
http://unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns
HTH,
Dave
--
@Dave DeLong
Sorry, didn't get your previous message. I think something may be wrong
with my email account. ;) In any event, here is my current code:
NSCalendarDate *date = [NSCalendarDate calendarDate];
NSString *dateString = [date descriptionWithCalendarFormat:@"%Y-%m%d"];
Now I am wondering how I can take that special formatted string and save it
back into NSCalendarDate or NSDate (knowing how it was formatted). I looked
up some information regarding dateFromString but it returns null when I pass
it my string. Though I could be doing something wrong regarding
dateFromString.
Thanks for any help.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden