init] returning date an hour in the past?

后端 未结 4 1051
感情败类
感情败类 2021-01-16 06:49

When I call

NSDate *now = [[NSDate alloc] init]; 

in order to get the current date and time, I check it with:

NSLog(@\"Dat         


        
相关标签:
4条回答
  • 2021-01-16 07:21

    Use NSDateFormatter to localize the date:

    NSLog(@"%@",[NSDateFormatter localizedStringFromDate:[NSDate date] dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle]); 
    
    0 讨论(0)
  • 2021-01-16 07:29

    I've seen that behavior on the DatePicker running on iOS 4.1 devices while on iOS 4.0 and previous it does not happen. I can't confirm it is actually the same bug.

    But I suggest you check whether is related with the acknowledged by Apple bug regarding dates/summer time/4.1 by running that code on < 4.1. Then you will need to decide whether to hack a fix for that particular version/dates or wait for the next release of the SDK to fix it and not support 4.1 devices...

    The bug I'm talking about I believe only happens while passing dates within the summer time period (2010: 28th March - 31st October)

    0 讨论(0)
  • 2021-01-16 07:30

    Maybe your timezone is wrong in your iPhone simulator. Press the home button, go to settings.app and correct it ;)

    0 讨论(0)
  • 2021-01-16 07:37

    Use NSDate *now = [NSDate date];

    I am using it and giving me perfect result.

    0 讨论(0)
提交回复
热议问题