我有ios应用程序与datetimepicker,我将日期存储到数据库与“日期”类型。所以它会存储一些数NSDATE日期时间选择器
日来自数据库和显示的NSString这样的:2012-06-25 6时45分06秒+0000
这会给我GMT 0,我想这个时候GMT +5:30并将其显示到texfield。
strTime = @"2012-06-25 06:45:06 +0000";// thats comes form database like this.
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"yyyy-MM-dd hh:mm"]; NSDate *myDate = [dateFormat dateFromString:strTime];
NSString *strDate = [dateFormat stringFromDate:myDate]; NSLog(@"%@", strDate);
txtTime.text = strDate;
结果将是(空)我想显示像2012-06-25 12时15分06秒(与GMT 5的时间:30)
查看此问题中的[answer](http://stackoverflow.com/a/7259553/1351911)。它会回答你的困惑。 –
我已经使用'NSDateFormatter'将nsdate用于nstring,然后将nstring用于nsdate - 但它会给(null)值。 – user1472076
我不确定。你可以发布一些代码吗? –