Akash Raghani
Akash Raghani

Reputation: 557

Date format in swift language

In swift Language
And I want to get date in this format:

yyyy-MM-ddTHH:mm:ss.fffffff+zzz

Upvotes: 0

Views: 536

Answers (1)

MirekE
MirekE

Reputation: 11555

Try this format:

yyyy-MM-dd'T'HH:mm:ss.Sz

S is for fractional seconds and z for timezone. Please note that T is escaped

To convert NSDate back to this format:

var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSxxx"
dateFormatter.lenient = false
dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
dateFormatter.timeZone = NSTimeZone(abbreviation: "GMT")
dateFormatter.stringFromDate(NSDate()) // returns "2015-09-16T13:51:53.316000+00:00"

Upvotes: 4

Related Questions