Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 620 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Swift full date with milliseconds

#1
Is any way to print full date with milliseconds?

For example, I'm doing this:

print("\(NSDate())")

But I'm just get this:

2016-05-09 22:07:19 +0000

How can I get the milliseconds too in the full date?
Reply

#2
**Updated for Swift 3**

let d = Date()
let df = DateFormatter()
df.dateFormat = "y-MM-dd H:mm:ss.SSSS"

df.string(from: d) // -> "2016-11-17 17:51:15.1720"


When you have a `Date` `d`, you can get the formatted string using a NSDateFormatter. You can also use a formatter to turn a string date based on your format into a `Date`

See this chart for more on what dateFormat can do

[To see links please register here]

Reply

#3
**Swift 5** to/from Timestamp String Extension

extension String {
static func timestamp() -> String {
let dateFMT = DateFormatter()
dateFMT.locale = Locale(identifier: "en_US_POSIX")
dateFMT.dateFormat = "yyyyMMdd'T'HHmmss.SSSS"
let now = Date()

return String(format: "%@", dateFMT.string(from: now))
}

func tad2Date() -> Date? {
let dateFMT = DateFormatter()
dateFMT.locale = Locale(identifier: "en_US_POSIX")
dateFMT.dateFormat = "yyyyMMdd'T'HHmmss.SSSS"

return dateFMT.date(from: self)
}
}
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through