在objective-c中,以下代码使用date
API生成UTC日期时间信息.
NSDate *currentUTCDate = [NSDate date]
然而,在Swift ,
let date = NSDate.date()
结果为本地日期和时间.
我有两个问题:
- 如何在
NSDate
个对象中获得UTC时间和本地时间(date
给出了本地时间). - 如何从
NSDate
物体上获得秒的精度.
EDIT 1: Thanks for all the inputs but I am not looking for NSDateFormatter
objects or string values. I am simply looking for NSDate objects (however we cook them up but that's the requirement).
See point 1.