【发布时间】:2011-06-18 11:23:58
【问题描述】:
- (IBAction) buttonPressed {
NSDate *selected = [datePicker date];
NSString *message = [[NSString alloc] initWithFormat:@"The date and time you selected is: %@", selected];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Date and Time Selected" message:message delegate:nil cancelButtonTitle:@"Yes, I did!" otherButtonTitles:nil];
[alert show];
[alert release];
[message release];
所以我的问题是下一个...如何在 Objective C 中使用 Datepicker 指定时区? 现在,如果我从 DatePicker 中选择一些值并按下显示警报的按钮 - 时间是错误的。这可能是因为时区不正确,但我不确定。那么任何想法都会很棒。在下图中,您可以看到我选择了 2:14 PM (14:14),但一个人说现在是 11:14,时区是 +000
更新 1 我已经对我的代码添加了一些更改,但仍然没有...
- (IBAction) buttonPressed {
NSDate *selected = [datePicker date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSTimeZone *tz = [NSTimeZone systemTimeZone];
[dateFormatter setTimeZone:tz];
NSString *formattedDate = [dateFormatter stringFromDate:selected];
NSString *message = [[NSString alloc] initWithFormat:@"The date and time you selected is: %@", formattedDate];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Date and Time Selected"
message:message delegate:nil cancelButtonTitle:@"Yes, I did!" otherButtonTitles:nil];
[alert show];
[alert release];
[message release];
[dateFormatter release];
【问题讨论】:
标签: iphone objective-c cocoa-touch datepicker