【发布时间】:2014-02-25 12:29:05
【问题描述】:
我正在尝试将日期字符串从数据库更改为日期(mm.dd.yy)和时间(am pm)。 这样我就可以从 sqlite 获取日期时间:
rs=[db executeQuery:@"select *,strftime('%m.%d.%Y %H:%M',update_date) AS DATETIME from sales_order where deleted=0 and status=1 and customer_id=? order by order_id desc",custId];
我得到日期时间字符串:
NSString *dateTimeString = [rs stringForColumn:@"DATETIME"];//from nslog 02.25.2014 14:41
然后我启动日期格式化程序并获取日期:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[self getCurrentLocale]];
[dateFormatter setDateFormat:@"mm dd YY hh:mm a"];//it is nil,i am stuck here also tried with mm.dd.YY hh:mm a
NSDate *date = [dateFormatter dateFromString:dateTimeString];
任何建议 谢谢
【问题讨论】:
-
你有多个“.”在 NSLog 显示的日期字符串中。但它们不会出现在您的
dateFormat中。另外还有两个“mm”,月份和分钟,一个应该是大写的。如果我记得很清楚(没试过),你应该使用类似的东西:MM'.'dd'.'YY hh:mm a。 -
你的问题解决了吗?
标签: iphone ipad nsdate nsdateformatter