Search code examples
iosobjective-crubymotion

How to convert UTC


I am building an iOS app (in Rubymotion). I got incoming dates from an API that I would like to parse and save locally.

This is the dateformat:

2014-08-18T20:51:00.000+02:00

I try to parse it with this code but I only get nil back (I tried with and without setting timezone):

df = NSDateFormatter.alloc.init
df.setTimeZone(NSTimeZone.timeZoneWithAbbreviation("UTC"))
df.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")

date = df.dateFromString(date)

Solution

  • Try this:

    df.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");