iOS:日期格式 - 2012年9月20日 [英] iOS : Date format - 20-Sep-2012

查看:133
本文介绍了iOS:日期格式 - 2012年9月20日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望以字符串2012-11-22 10:19:04的格式显示2012年9月20日的日期。我该怎么办?是否有内置的iOS方法?

I want to display the date in the format "20-Sep-2012" from the string "2012-11-22 10:19:04". How can i do this? Is there any in-built method for iOS?

推荐答案

NSString *myString = @"2012-11-22 10:19:04";
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";     
NSDate *yourDate = [dateFormatter dateFromString:myString];
dateFormatter.dateFormat = @"dd-MMM-yyyy";
NSLog(@"%@",[dateFormatter stringFromDate:yourDate]);

您的日志会像这样打印。 2012年11月22日

your log will print like this. 22-Nov-2012

这篇关于iOS:日期格式 - 2012年9月20日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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