I have an NSDate
object that I am sending to an API that we use. Our app is used across the world, so the API is wanting the date to be in UTC, e.g.:
"/Date(1481704200000)/"
However, the date needs to have the timezone offset taken into account since the API/server is not doing this for us. If we don't do this, the date is incorrect when we view it on the server.
I am doing the following, which seems to produce an incorrect date:
// Offsetfloat timezoneoffset = [[NSTimeZone localTimeZone] secondsFromGMT];// DateCFTimeInterval startDate = [[NSDate date] timeIntervalSince1970];startDate = startDate - timezoneoffset;NSString *dateStarted = [NSString stringWithFormat:@"/Date(%.0f000)/", startDate];
How can I correctly take the local time zone into account and create a correctly formatted UTC date string?