NSDate - 更改年份值 [英] NSDate - Changing the year value
本文介绍了NSDate - 更改年份值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要更改NSDate对象。我基本上做的是改变年份值。
I need to change a NSDate object. What I am basically doing is changing the year value.
例如:
NSString *someYear = @"2093";
NSDate *date = [NSDate date]; // Gets the current date.
... Create a new date based upon 'date' but with specified year value.
所以从'init'返回2011-03-06 22:17:50 +0000来自init,我想用2093-03-06 22:17:50 +0000创建一个日期。
So with 'date' returning 2011-03-06 22:17:50 +0000 from init, I would like to create a date with 2093-03-06 22:17:50 +0000.
但是我希望这个文化尽可能保持中立,所以它可以在任何时区工作。
However I would like this to be as culturally neutral as possible, so it will work whatever the timezone.
谢谢。
推荐答案
Take看看 NSCalendar
,尤其是组件:fromDate:
和 dateFromComponents:
方法。
Take a look at NSCalendar
, especially components:fromDate:
and dateFromComponents:
methods.
这篇关于NSDate - 更改年份值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文