所以我从后端得到这个答案:
{ "SERVERDateTimeGet": { "Return Code" : 0,
"Return String" : "No Error",
"Year" : 2018,
"Month" : 8,
"Day" : 29,
"Hour" : 14,
"Minute" : 16,
"Second" : 20,
"Daylight" : 1,
"NTP" : 0,
"NtpDhcp" : 0,
"NtpServers" : "time.google.com",
"Timezone" : "EET-2EEST,M3.5.6/0:01,M9.1.5" }
}
(我知道这很糟糕,非常糟糕,但就我所知)
我有这种方法:
func makeDate(year: Int, month: Int, day: Int, hr: Int, min: Int, sec: Int) -> Date {
let calendar = Calendar(identifier: .gregorian)
// calendar.timeZone = TimeZone.current
let components = DateComponents(year: year, month: month, day: day, hour: hr, minute: min, second: sec)
//let components = DateComponents(timeZone: TimeZone.current, year: year, month: month, day: day, hour: hr, minute: min, second: sec)
return calendar.date(from: components)!
}
但是当我得到日期时,它又是3个小时了。 我认为这是因为时区,但是如您所见,我没有使用时区。 还有其他方法可以生成日期,也可以只使用当前的整数?