NSDate、NSString、long转化

- (NSDate *)dateFromString:(NSString *)dateString{

    

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

    

    [dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss"];

    

    NSDate *destDate= [dateFormatter dateFromString:dateString];

    

    return destDate;

    

}


- (NSString *)stringFromDate:(NSDate *)date{

    

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

    

    //zzz表示时区,zzz可以删除,这样返回的日期字符将不包含时区信息。

    

    [dateFormatter setDateFormat:@"MM-dd HH:mm"];

    

    NSString *destDateString = [dateFormatter stringFromDate:date];

    

    return destDateString;

    

}

-(NSString *)stringFromValue:(NSString *)value{

    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[value longLongValue]];

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

    [formatter setDateFormat:@"MM-dd HH:mm"];

    

    NSString *date = [formatter stringFromDate:confromTimesp];

    return date;

}

你可能感兴趣的:(NSString,ios开发,NSDate,时间戳字符串转换)