Quantcast
Channel: Converting [NSDate date] to a localized UTC date string - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Converting [NSDate date] to a localized UTC date string

$
0
0

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?


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles



Latest Images