NSDate is not returning my local Time zone /default time zone of device

后端 未结 7 1968
孤城傲影
孤城傲影 2020-11-27 16:02

My local and default time zone is GMT +5 but when I get date and time by NSDate it return me GMT date and time.

For example the code and output from my code while

相关标签:
7条回答
  • 2020-11-27 16:35

    This works well for me to get the date in my timezone and format it just like I want it:

    NSDate* gmtDate = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"America/Los_Angeles"]];
    [formatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
    NSString *dateString = [formatter stringFromDate:gmtDate];
    
    0 讨论(0)
提交回复
热议问题