convert NSstring date to UTC date

后端 未结 2 1973
栀梦
栀梦 2021-01-20 04:08

i need to convert some date that i have in NSString to NSString in this format: yyyy-MM-dd HH:mm:ss zzz i write this code:

相关标签:
2条回答
  • 2021-01-20 04:20

    try this method..

    -(NSString *)getUTCFormateDate:(NSString *)localDate
    {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"dd/MM/yyyy"];
    
        NSDate *dateFormatted = [dateFormatter dateFromString:localDate];
        NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
        [dateFormatter setTimeZone:timeZone];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSString *dateString = [dateFormatter stringFromDate:dateFormatted];
        [dateFormatter release];
        return dateString;
    }
    
    0 讨论(0)
  • 2021-01-20 04:36

    i think, Here GMT show Standard time and GMT and UTC both are same. please look on below links: http://wwp.greenwichmeantime.com/ http://www.worldtimeserver.com/convert_time_in_UTC.aspx

    thanks

    0 讨论(0)
提交回复
热议问题