如何将日期初始化为NSdate? [英] How can I initialize a date to NSdate?
本文介绍了如何将日期初始化为NSdate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我想以mm/dd/yyyy
的格式给出12/11/2005
.我可以直接将12/11/2005
初始化为NSDate
吗?有帮助吗?
I want to give, for example, 12/11/2005
in the format of mm/dd/yyyy
. Can I initialize 12/11/2005
to NSDate
directly? Any help?
它发出警告,当我声明为
it gives a warning and crashes when I declare it as
NSDate *then = [NSDate dateWithNaturalLanguageString:02/11/2009 locale:nil];
推荐答案
您需要做的是这样的事情:
What you need to do is something like this:
NSDateFormatter *mmddccyy = [[NSDateFormatter alloc] init];
mmddccyy.timeStyle = NSDateFormatterNoStyle;
mmddccyy.dateFormat = @"MM/dd/yyyy";
NSDate *d = [mmddccyy dateFromString:@"12/11/2005"];
NSLog(@"%@", d);
这篇关于如何将日期初始化为NSdate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文