how to use nsdateformatter to Venezuela

ぐ巨炮叔叔 提交于 2019-11-27 16:29:11

I use following code to get desired timezone-converted datetime:

- (NSString *) getUTCDate : (NSString *) inputDate
{
    NSDateFormatter *utcDateFormatter = [[NSDateFormatter alloc] init];
    [utcDateFormatter setDateFormat:@"dd-MMM-yyyy HH:mm:ss Z"];
    [utcDateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
  //  [utcDateFormatter setTimeZone :[NSTimeZone timeZoneForSecondsFromGMT: 0]];        
    // utc format
    NSDate *dateInUTC = [utcDateFormatter dateFromString: inputDate];        

    return dateInUTC;
}

where dateInUTC is the date in GMT timezone.

You need to replace your own timezone in call [NSTimeZone timeZoneWithName:@"UTC"] and it should work.

Simply change one line of code in your code...

[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];

This will set time format in universal which doesnot change with region or day light saving time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!