Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift日期从时区转换_Ios_Swift_Date - Fatal编程技术网

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!)")