Skip to content

Instantly share code, notes, and snippets.

@jeffery812
Created April 8, 2020 05:59
Show Gist options
  • Select an option

  • Save jeffery812/ef534ac0b7f30f2ff44c4f66ad0afc4a to your computer and use it in GitHub Desktop.

Select an option

Save jeffery812/ef534ac0b7f30f2ff44c4f66ad0afc4a to your computer and use it in GitHub Desktop.

Revisions

  1. jeffery812 created this gist Apr 8, 2020.
    10 changes: 10 additions & 0 deletions DateExtensions
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    // https://stackoverflow.com/questions/33145005/swift-nsdateformatter-not-using-correct-locale-and-format/61094162#61094162

    extension Date {
    var timestamp: String {
    let dataFormatter = DateFormatter()
    dataFormatter.locale = Locale(identifier: "en_US_POSIX")
    dataFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSSS"
    return String(format: "%@", dataFormatter.string(from: self))
    }
    }