1

How can I convert 12 Oct 2018 at 10:45:46 AM to SwiftDate DateInRegion? My code returns 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)
1

1 Answer 1

2

check your dateformat , is not available, the correct format is

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

Sign up to request clarification or add additional context in comments.

1 Comment

i just changed the EEE to MM and it works now. thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.