Get Current date & time with [NSDate date]

前端 未结 1 1669
情话喂你
情话喂你 2021-01-30 03:49

My system\'s date time is 26 May 22:55 but when i get date with [NSDate date] date time is 27 May 02:35

is it because of time zone ?

if yes how

1条回答
  •  孤街浪徒
    2021-01-30 04:36

    NSLocale* currentLocale = [NSLocale currentLocale];
    [[NSDate date] descriptionWithLocale:currentLocale];  
    

    or use

    NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init]; 
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    // or @"yyyy-MM-dd hh:mm:ss a" if you prefer the time with AM/PM 
    NSLog(@"%@",[dateFormatter stringFromDate:[NSDate date]]);
    

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