如何在iOS中将字符串转换为日期格式? [英] how to convert string into date format in iOS?

查看:53
本文介绍了如何在iOS中将字符串转换为日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自Web服务的字符串,例如 12/31/2013 09:12:15 A.M .现在,我要像 12 Dec 2013 09:12:15 A.M 那样转换它.在iOS中使用 NSDAteFormatter

I have string from web service like 12/31/2013 09:12:15 A.M. Now I Want convert it like 12 Dec 2013 09:12:15 A.M. with the use of NSDAteFormatter in iOS

推荐答案

我给您答案,但对您的问题太基础了,并且通过简单的搜索即可轻松找到其解决方案,对此表示不满.

I'm giving you the answer, but downvoting your question for being too elementary and whose solution could easily found with a simple search.

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/yyyy hh:mm:ss a"];
NSDate *date = [formatter dateFromString:myDateString];
[formatter setDateFormat:@"dd MMMM yyyy aa:mm:ss a"];
NSString *newDate = [formatter stringFromDate:date];

这篇关于如何在iOS中将字符串转换为日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆