Remove timezone offset from date in iOS

I need to get the current NSDate.date and delete the time zone and NSDate.date it as GMT date

 NSDate.date 

returns 2012-10-11 11:27:09 -0700

I need this: 2012-10-11 11:27:09 +0000

+4
source share
1 answer

NSDate.date returns a date with the current date and time stored as GMT.

If you want to format the date as a string and show the time in GMT, you must use NSDateFormatter and set the locale to GMT:

 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"GMT"]]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"]; NSString *dateAsString = [formatter stringFromDate:[NSDate date]]; 
+6
source

Source: https://habr.com/ru/post/1439234/


All Articles