Aug 5, 2010

Objective C - NSString NSDate Conversion






NSDate convert to NSString:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *strDate = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"%@", strDate);[dateFormatter release];

Result:
2010-08-04 16:01:03


NSString convert to NSDate:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *date = [dateFormatter dateFromString:@"2010-08-04 16:01:03"];
NSLog(@"%@", date);[dateFormatter release];


Result:
2010-08-04 16:01:03 +0800


6 comments:

Prostate Gland Problems said...

Great, I never knew this, thanks.

school grants said...

this post is very usefull thx!

free government grants said...

Pretty nice post. I just stumbled upon your blog and wanted to say that I have really enjoyed browsing your blog posts. In any case I’ll be subscribing to your feed and I hope you write again soon!

weight said...

mFd
Sky

Free WP Themes said...

Nice brief and this mail helped me alot in my college assignement. Thank you for your information.

weight said...

i see what you did there

Post a Comment

Twitter Delicious Facebook Digg Google Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Hostgator Coupon Code