DateFormat

public struct DateFormat

A dateformatter which provides default DateFormatter converts string to Date object.

  • Returns a date with given string, DateFormat#parse(str:) use serveral formats to retrieve the date inforamtion from the string.

    1. Custom format yyyy-MM-dd HH:mm:ss ZZZZ
    2. ISO8601 format yyyy-MM-dd’T'HH:mm:ssZZZZZ
    3. RFC2822 format EEE, d MMM yyyy HH:mm:ss ZZZ
    4. CTime format EEE MMM d HH:mm:ss yyyy

      DateFormat.parse(Sun, 19 Mar 2017 01:02:04 +0800) #=> 2017-03-19 01:02:04 +0800

    Declaration

    Swift

    public static func parse(str: String) -> Date?

    Parameters

    str

    A given string contains the date information

    Return Value

    A date object or nil