Ios Swift日期从时区转换
打印此Ios Swift日期从时区转换,ios,swift,date,Ios,Swift,Date,打印此2018-07-24T15:06:26 可选(2018-07-24 06:06:26+0000) 我要现在日期值2018-07-24T15:06:26 但是字符串到日期没有时区 我必须使用totimeintervalences,因此nowdate必须有时区Date是一个特定的时间点,它独立于时区。如果打印日期值,它将始终独立于任何日历或时区。它将为您(KST)和我(IST)提供相同的值。使用DateFormatter格式化时区时,可以指定时区 dateFormatter.dateForm
2018-07-24T15:06:26
可选(2018-07-24 06:06:26+0000)
我要现在日期值2018-07-24T15:06:26
但是字符串到日期没有时区
我必须使用to
timeintervalences
,因此nowdate必须有时区Date
是一个特定的时间点,它独立于时区。如果打印日期值,它将始终独立于任何日历或时区。它将为您(KST)和我(IST)提供相同的值。使用DateFormatter
格式化时区时,可以指定时区
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
dateFormatter.timeZone = TimeZone(abbreviation: "KST")
let nowstring = dateFormatter.string(from: Date())
let nowdate = dateFormatter.date(from: nowstring)
print(nowstring)
print(nowdate)
let today = NSDate()
print("\(today)")
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let nowDatestring = formatter.string(from: today)
formatter.timeZone = TimeZone(abbreviation: "KST")
let kstDate = formatter.date(from: nowDatestring)
print("\(kstDate!)")
formatter.timeZone = TimeZone(abbreviation: "PST")
let pstDate = formatter.date(from: nowDatestring)
print("\(pstDate!)")
formatter.timeZone = TimeZone(abbreviation: "IST")
let istDate = formatter.date(from: nowDatestring)
print("\(istDate!)")