Skip to content

Instantly share code, notes, and snippets.

@jbarros35
Created April 25, 2018 14:42
Show Gist options
  • Select an option

  • Save jbarros35/0562bf47f162c4351d6f05b602203c7d to your computer and use it in GitHub Desktop.

Select an option

Save jbarros35/0562bf47f162c4351d6f05b602203c7d to your computer and use it in GitHub Desktop.

Revisions

  1. jbarros35 created this gist Apr 25, 2018.
    17 changes: 17 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    // REMARK: format date for better display
    func convertDate(date: Date) -> String? {
    let dateFormatterGet = DateFormatter()
    dateFormatterGet.dateFormat = "yyyyMMdd HH:mm:ss"
    let dateString = dateFormatterGet.string(from: date)
    return dateString
    }

    // REMARK: server sends dates on JS string format
    func convertJSDate(date: String) -> String? {
    let dateFormatterGet = DateFormatter()
    dateFormatterGet.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
    if let date = dateFormatterGet.date(from: date) {
    return convertDate(date: date)
    }
    return nil
    }