我使用Xcode8 Beta4将Swift2.3中开发的项目转换为Swift3.0。其中我有方法将日期转换为字符串,但它无法将其转换。类型'TimeZone'在Swift3中没有成员'local'
class func convertDateToString(_ date:Date, dateFormat:String) -> String?
{
let formatter:DateFormatter = DateFormatter();
formatter.dateFormat = dateFormat;
formatter.timeZone = TimeZone.local
let str = formatter.string(from: date);
return str;
}
此外,在文件没有名为local
成员。
有什么办法可以直接使用TimeZone
?或者我们必须使用NSTimeZone
?
试试这个formatter.timeZone =。本地 –
'NSTimeZone.local'的作品,同为'.system'和'.default'。您可以在Apple提交错误报告。 –
@ Anbu.Karthik:'.local'也不起作用。 – technerd