سؤال

I am getting total number of seconds for the timezone but not getting it is ahead of GMT Or behind to GMT. Here is my code.

NSDate *sourceDate = [NSDate dateWithTimeIntervalSinceNow:3600 * 24 * 60];
NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
int totalSeconds = [[NSTimeZone systemTimeZone] secondsFromGMT];
NSLog(@"sourceDate=%@ timeZoneOffset=%d", sourceDate, totalSeconds);

I want to know it is GMT + or GMT - For example India time zone is GMT+5:30 i am getting total 19800 seconds with this code but how to know it is GMT+ .

Any help will be appreciated.

هل كانت مفيدة؟

المحلول

The seconds returned is an integer value, which will be positive or negative depending on the offset from the GMT.

Also, you might want to read through the documentation. It discusses this in the very first section.

نصائح أخرى

The result you are getting are correct, if it's GMT- you will get a negative value, you can use the following check:

if (totalSeconds >= 0){
    // it's GMT+
} else {
    // it's GMT-
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top