how to use nsdateformatter to Venezuela

后端 未结 2 483
后悔当初
后悔当初 2020-12-04 04:32

I\'m trying to schedule a date on the calendar, which has a start time and an end time, everything works fine if the time zone is in the U.S., and the date the change does n

2条回答
  •  醉话见心
    2020-12-04 04:58

    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.

提交回复
热议问题