获取国标时间,时间格式转化

+ (NSString *)currentGMT {

    NSDate *date = [NSDate date];

    NSTimeZone *tzGMT = [NSTimeZone timeZoneWithName:@"GMT"];

    [NSTimeZone setDefaultTimeZone:tzGMT];

    NSDateFormatter *iosDateFormater=[[NSDateFormatter alloc]init];

    iosDateFormater.dateFormat=@"EEE MMM dd yyyy HH:mm:ss 'GMT+0800'";

    iosDateFormater.locale=[[NSLocale alloc]initWithLocaleIdentifier:@"en_US"];

    return [iosDateFormater stringFromDate:date];
}
//Dec 11, 2019 5:56:21 PM   ===>  2019-12-11 17:56:21
- (NSString *)timeFormatConversion:(NSString *)dateString {

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"MMM dd, yyyy hh:mm:ss aa";
    formatter.locale=[[NSLocale alloc]initWithLocaleIdentifier:@"GB"];
    
    NSDate *date = [formatter dateFromString:dateString];
    
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    return [dateFormat stringFromDate:date];
}

 

你可能感兴趣的:(获取国标时间,时间格式转化)