In Swift, you can use DateFormatter
to convert date string to Date
type, and then convert it to any other format. Here's an example:
main.swift320 chars10 lines
This will output the date string in the format "yyyy-MM-dd HH:mm:ss:SSS". Note that we set the dateFormat
of the DateFormatter
to match the input date string. The SSSSSS
in the format string is used to represent fractional seconds with microsecond precision (six digits after the decimal point). The Z
at the end of the format string represents the time zone.
gistlibby LogSnag