Creating NSDate object with specific time zone

前端 未结 1 1468
广开言路
广开言路 2021-01-27 18:39

I\'ve written a method that accepts a NSDate object and should turn it into a NSDate object with EST time zone. The way I\'ve seen other people accomplish this is by using a dat

1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-27 19:07

    NSDate values do not have an associated time zone, they represent an abstract moment in time. So "a NSDate object with EST time zone" isn't a thing that exists. Time zones only come into play when formatting them for output, or trying to do calendar-based math.

    NSLog always uses UTC when printing its output.

    So you're taking a moment in time, formatting it to a string in a particular time zone, and then parsing it back into the same moment in time. That's working as intended.

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