[英]Swift string convert to SwiftDate
How can I convert 12 Oct 2018 at 10:45:46 AM
to SwiftDate DateInRegion
? 如何将
12 Oct 2018 at 10:45:46 AM
10:45:46转换为SwiftDate DateInRegion
? My code returns nil: 我的代码返回nil:
let ds = "12 Oct 2018 at 10:45:46 AM"
let region = Region(tz: TimeZone.current,
cal: CalendarName.gregorian.calendar,
loc: Locale.init(identifier: "en"))
let format = DateFormat.custom("EEE, dd MM yyyy HH:mm:ss zzz")
var str = ds.date(format: format, fromRegion: region)
check your dateformat ,
is not available, the correct format is 检查您的dateformat
,
不可用,正确的格式是
let ds = "12 Oct 2018 at 10:45:46 AM"
let format = DateFormat.custom("dd MMM yyyy 'at' HH:mm:ss a")
for additional info you get old answered from SO.for dateformats you get detailed answer from here 对于其他信息,您可以从SO中获取旧答案 。对于dateformats,您可以从此处获取详细答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.