将NSString转换为日期 [英] Converting NSString to Date
本文介绍了将NSString转换为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个字符串:date1 = 3-3-2011;
I have two strings: date1 = 3-3-2011;
,我想转换到2011年3月3日并显示在标签中。 / p>
and i want to convert in to 3-March-2011 and display it in label.
NSString *myString = 3-3-2011;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"d-MM-YYYY"];
NSDate *yourDate = [dateFormatter dateFromString:myString];
//now format this date to whatever you need…
[dateFormatter setDateFormat:@"d-MMM-YYYY"];
NSString *resultString = [dateFormatter stringFromDate:yourDate];
[dateFormatter release];
但yourdate = 2010-12-25 18:30:00 +0000
but yourdate = 2010-12-25 18:30:00 +0000
resultstring = 2010年12月26日
resultstring = 26-Dec-2010
我想要2010年3月3日
i want 3-March-2010
请帮助!
推荐答案
也许你应该这些文章;
Maybe you should these articles;
NSDate和NSDateFormatter - 短格式日期和时间在iphone sdk
http://en.wikipedia.org/wiki/Calendar_date#List_of_the_world_locations_by_date_format_in_use
http://iphonedevelopertips.com/cocoa/date-formatter-examples.html
这篇关于将NSString转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文