Skip to content

Instantly share code, notes, and snippets.

@zhihuitang
Created April 8, 2020 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhihuitang/ef534ac0b7f30f2ff44c4f66ad0afc4a to your computer and use it in GitHub Desktop.
Save zhihuitang/ef534ac0b7f30f2ff44c4f66ad0afc4a to your computer and use it in GitHub Desktop.
// 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))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment