- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我已经在其他类似的帖子中尝试过这些建议,但无济于事。这是情况:
我有一个像这样的 NSString:
Fri November 18, 2011
我正在尝试将其转换为这样的日期:
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"EE MMMM d, YYYY"];
NSDate *myDate = [df dateFromString: dateString];
但是生成的 myDate 变量包含这个:
2010-12-31 00:00:00 +0000
有谁知道为什么从 dateFromString 中选出了错误的日期?字符串是 11 月 18 日,转换后的日期是 12 月 31 日……
谢谢大家!
最佳答案
您需要使用 yyyy
作为年份,而不是 YYYY
。
来自Apple reference :
A common mistake is to use YYYY. yyyy specifies the calendar year whereas YYYY specifies the year (of "Week of Year"), used in the ISO year-week calendar. In most cases, yyyy and YYYY yield the same number, however they may be different. Typically you should use the calendar year.
为了正确,您还必须将 EE
更改为 EEE
。尽管它们在我的测试中产生了相同的结果。
关于iphone - NSDateFormatter dateFromString 给出了错误的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8186833/
我正在使用此代码将字符串转换为日期: +(NSDate*)dateTexteFromString:(NSString*)someString { NSDateFormatter *df = [
我有一个将 NSString 转换为 NSDate 的函数。 + (NSDate *)getNSDateFromString:(NSString *)strDate andFormat:(NSStri
我正在使用 NSDateFormatter 的 dateFromString,但是当它给出字符串时,它会输出不同的小时。 代码 NSDateFormatter *dateformatter = [[N
我绝对不是 NSDateFormatter 或 NSDate 的新手,但这完全难倒了我。我到底是怎么弄错开火日期的? NSDateFormatter *firedateFormat = [[NSDat
尝试将字符串传递给 NSDateFormatter dateFromString 方法时发生崩溃。 我查看了文档,但没有看到任何可以解释问题所在的内容。 NSError * error
我正在使用 NSDateFormatter 的 dateFromString,但是当它被赋予字符串“2013-03-06”时,它吐出一个 NSDate“2012-03-06 00:00:00 CST”
2014/03/30 02:00 -> 02:59 我正在解析 CSV 以训练基本神经网络。每行对应一分钟。该代码可以毫无问题地解析 2014 年的剩余时间,但那一小时的结果为 nil 值。符号上没有
我正在尝试将字符串转换为日期,但结果是不正确的日期。 let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "dd MMM
我有以下代码: NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat =
我正在尝试使用 NSDate dateFromString 方法,但收到警告并且它导致应用程序崩溃。代码如下: NSString *pickerDate = [NSString stringWithF
这是我的NSString, myDate : 2011-06-07 11:23:47 0000 这是代码, NSTimeZone *currentDateTimeZone = [NSTimeZone
美好的一天, 我有一个NSDateFormatter,它似乎不喜欢我尝试转换的特定字符串。这个特定的实例是 2009-10-16T09:42:24.999605 我所有其他日期的格式都相同,并且可以解
以下代码: NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; dateFormatter.d
请用以下代码帮助我。我想做的就是看到两个日期之间的时间(4:42:55)相差不到24小时,所以我不在乎日期。 谢谢 NSLog(@"error code"); NSDate *now = [[NSDa
我有以下代码: NSDateFormatter *dateFormater = [[NSDateFormatter alloc] init]; [dateFormater setDateFormat:
在 swift 中使用 dateFromString 时,某些值得到 nil。我搜索了很多但徒劳无功。 以下是我的代码: let strDate = self.sortedDict.valueForK
- (NSDate*) parseTime:(NSString*) time { NSDateFormatter* dateFormatter = [[NSDateFormatter allo
我知道这个问题已经在 SO 上讨论过很多次,但没有一个结果能解决我的问题。这是代码片段, NSDateFormatter* df = [[NSDateFormatter alloc]init]; [d
我知道对此有很多问题,但似乎没有一个答案对我有用。这是我的代码(iOS SDK 6.0) NSDateFormatter *df = [NSDateFormatter alloc]; [df setD
我知道问题已经存在,但给出的答案对我没有帮助。 生日的值为:Jun 29, 2013, 8:45 AM 这是我的代码: NSDate* now = [[NSDate alloc] init]; NSD
我是一名优秀的程序员,十分优秀!