如何更改存储在字符串中的日期格式?目标c
可能的重复:
如何转换 NSString 中的日期时间格式?
我已将日期存储在字符串中从json解析。日期格式为 2011-1-24。现在我想转换成 MM-dd-YYYY 格式。为此,我正在使用此代码
NSString *stringDate =[NSString stringWithFormat:@"%@",[list_date objectAtIndex:indexPath.row]];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM-dd-yyyy"];
NSDate *date = [dateFormatter dateFromString:stringDate];
NSString *newDate = [dateFormatter stringFromDate:date];
,但它显示空值。这段代码有什么问题?
提前致谢...
Possible Duplicate:
how to convert datetime format in NSString?
I have stored date in string from json parsing. The format of date is 2011-1-24. Now i want to convert into MM-dd-YYYY format. For that i am using this code
NSString *stringDate =[NSString stringWithFormat:@"%@",[list_date objectAtIndex:indexPath.row]];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM-dd-yyyy"];
NSDate *date = [dateFormatter dateFromString:stringDate];
NSString *newDate = [dateFormatter stringFromDate:date];
But it show null value. What is problem in this code?
Thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尽管看起来相同,但它与 @Mayur Joshi 的答案不同。
这肯定对你有用。
我希望这对你有帮助。
如果您需要任何帮助,请在下面发表评论。
您也可以参考此链接以获得更多帮助。该链接与您想要的非常相似,只是目标日期格式不同。
如何将日期字符串转换为格式“17 Nov 2010”
It is different from @Mayur Joshi's answer though it looks to be same.
This is sure to work for you.
I hope this helps you.
If you need any help on this then please leave a comment below.
Also you can refer to this link for more help. This link is really similar to what you want, only the target date Format is different.
How to convert date string into format "17 Nov 2010"