iOS 5 在 DatePicker 中选择日期
我想在 DatePicker 中选择日期,但我遇到了 2 小时滞后的问题。
// String From Date
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterFullStyle];
[dateFormatter setDateStyle:NSDateFormatterFullStyle];
[dateFormatter setLocale:[NSLocale currentLocale]];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];
NSDate *dateSelected = [datePicker date];
NSString *dateChoisie = [dateFormatter stringFromDate:dateSelected];
NSDate *dateFinal = [dateFormatter dateFromString:dateChoisie];
NSLog(@"dateSelected = %@", dateSelected);
NSLog(@"dateChoisie = %@", dateChoisie);
NSLog(@"dateFinal = %@", dateFinal);
结果 :
2011-10-15 00:16:11.129 QuickEvent[25459:707] dateSelected = 2011-10-14 22:20:05 +0000
2011-10-15 00:16:11.132 QuickEvent[25459:707] dateChoisie = 2011-10-15 00:20:05 +0200
2011-10-15 00:16:11.138 QuickEvent[25459:707] dateFinal = 2011-10-14 22:20:05 +0000
I want to have in my DatePicker selected date, but I have a problem with lag of 2 hours.
// String From Date
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterFullStyle];
[dateFormatter setDateStyle:NSDateFormatterFullStyle];
[dateFormatter setLocale:[NSLocale currentLocale]];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];
NSDate *dateSelected = [datePicker date];
NSString *dateChoisie = [dateFormatter stringFromDate:dateSelected];
NSDate *dateFinal = [dateFormatter dateFromString:dateChoisie];
NSLog(@"dateSelected = %@", dateSelected);
NSLog(@"dateChoisie = %@", dateChoisie);
NSLog(@"dateFinal = %@", dateFinal);
Result :
2011-10-15 00:16:11.129 QuickEvent[25459:707] dateSelected = 2011-10-14 22:20:05 +0000
2011-10-15 00:16:11.132 QuickEvent[25459:707] dateChoisie = 2011-10-15 00:20:05 +0200
2011-10-15 00:16:11.138 QuickEvent[25459:707] dateFinal = 2011-10-14 22:20:05 +0000
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用这种格式。
例如,您可以将 TIME_ZONE_THAT_YOU_WANTED = -8 应用于基于纽约时区的时间
谢谢,
阿伦.
Try using this kind of formatting..
For an example you can apply TIME_ZONE_THAT_YOU_WANTED = -8 for New york timezone based time
Thanks,
Arun.