如何转换日期,如“2012-12-26”至“2012年12月26日”在iOS? [英] How to convert Date like "2012-12-26" to "december 26, 2012" in iOS ?

查看:87
本文介绍了如何转换日期,如“2012-12-26”至“2012年12月26日”在iOS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iOS中将日期 2012-12-26 转换为 2012年12月26日

I want to convert date 2012-12-26 to december 26, 2012 in iOS?

我使用的是websrvice,数据格式为 1990-12-26

I am using websrvice and the data comes in this format 1990-12-26.

我想将此更改为 2012年12月26日格式。

这是什么我正在做:

lbl_Rightside.text = [rootElement stringValueForNode:@"date"];
NSLog(@"lbl_Rightside is %@",lbl_Rightside.text);
[lbl_Rightside release];

1990-12-26获取此标签的日期。现在我想将日期更改为 2012年12月26日格式。

Getting date to this label on 1990-12-26. Now I want to change date to december 26, 2012 format.

非常欢迎来自专家的任何提示。

Any hints from experts would be very welcome.

推荐答案

你可以使用 NSDateFormatter 来做这类事情。第一个

you can use NSDateFormatter to do this kind of things. First


  1. 使用dateFromString将日期字符串转换为日期对象:
    method。

  2. 从日期转换为您想要的字符串使用stringFromDate:method

  3. 可以找到不同的格式字符串这里

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSDate *orignalDate   =  [dateFormatter dateFromString:YOUR_ORIGINAL_STRING];

[dateFormatter setDateFormat:@"MMMM dd, yyyy"];
 NSString *finalString = [dateFormatter stringFromDate:orignalDate];

[dateFormatter release]; //if not using ARC


这篇关于如何转换日期,如“2012-12-26”至“2012年12月26日”在iOS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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