UIDatePicker的时间选择器里的时区的问题

转自:http://www.cocoachina.com/bbs/simple/?t70445.html

初始化代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    NSDate *now = [NSDate date];
    [_datePicker setDate:now animated:NO];
}

显示代码:

- (IBAction)buttonPressed
{
    NSDate *selected = [_datePicker date];
    
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSString *theDate = [dateFormat stringFromDate:selected];
    
    NSString *message = [[NSString alloc] initWithFormat:@"The date and time you selected is: %@", theDate];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Date and Time Selected" message:message delegate:nil cancelButtonTitle:@"Yes, I did." otherButtonTitles:nil];
    [alert show];
}

 

posted on 2013-07-11 21:35  王培  阅读(469)  评论(0编辑  收藏  举报

导航