Get UTC time and local time from NSDate object

前端 未结 10 1021
夕颜
夕颜 2020-11-28 23:17

In objective-c, the following code results in the UTC date time information using the date API.

NSDate *currentUTCDate = [NSDate date]
         


        
10条回答
  •  囚心锁ツ
    2020-11-28 23:43

    The documentation says that the date method returns a new date set to the current date and time regardless of the language used.

    The issue probably sits somewhere where you present the date using NSDateFormatter. NSDate is just a point on a time line. There is no time zones when talking about NSDate. I made a test.

    Swift

    print(NSDate())
    

    Output: 2014-07-23 17:56:45 +0000

    Objective-C

    NSLog(@"%@", [NSDate date]);
    

    Output: 2014-07-23 17:58:15 +0000

    Result - No difference.

提交回复
热议问题