dateFromString return nil.
2014-12-03 15:52
309 查看
NSDateFormatter *dm = [[NSDateFormatter alloc] init]; [dm setDateFormat:@"yyyy-MM-dd HH:mm"]; NSString* dateTimeStr = [NSString stringWithFormat:@"%@ %@",_date, _time]; NSDate *sourceDate = [dm dateFromString:dateTimeStr];
(lldb) po dateTimeStr
2014-12-01 00:00
(lldb) po dm
<NSDateFormatter: 0x17005c470>
放狗搜:
If the device is set to AM/PM time and requested string format is set to @"yyyy-MM-dd HH:mm:ss" dateFromString will return nil.
If you set the locale to @"en_US" conversion will return correct date.
dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
[dateFormat setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *date = [dateFormat dateFromString:@"2013-02-14 09:30:00"];
复现条件:真机
地区调成:英国UK
时间格式调成:12小时制
语言:英语
相关文章推荐
- dateFromString永远返回nil的处理办法
- 解决 dateFromString 在真机上不显示
- IOS Date, NSDateFormatter, compare, dateFromString:mydatestr
- SpringMVC Failed to convert from type java.lang.String to type java.util.Date for value '2014-12-02'
- 'Conversion failed when converting date and/or time from character string.DB-Lib error message 241,
- Spring Mvc使用Jackson进行json转对象时,遇到的字符串转日期的异常处理(Can not deserialize value of type Date from String)
- org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from String value '2012-12-12 12:01:01': not a valid representation (error: Can not parse date "2012-12-
- Failed to convert from type java.lang.String to type java.util.Date for value………解决办法
- Boost::Date_time库和time_from_string()函数的使用
- 三十二,在iOS中[__NSCFCalendar components:fromDate:]: date cannot be nil,日期转换成NSDate对象为nil ,
- Failed to convert from type java.lang.String to type java.util.Date for value………解决办法
- dateFromString 函数造成时间差问题
- Parse Date-time From String With PHP & MySQL
- OC静态库里NSClassFromString得到nil的解决
- time value from 1970 to date string.
- NSClassFromString returns nil的问题
- dateFromstring
- Failed to convert from type java.lang.String to type java.util.Date for value解决办法
- Failed to convert from type java.lang.String to type java.util.Date for value………解决办法
- org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from String value '20Spring Jackson 反序列化Date时遇到的问题