时间戳和当前时间转换

1.把获取的时间转换成当前时间code

NSDate *dateNow = [NSDate date];
    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    NSInteger interval = [zone secondsFromGMTForDate:dateNow];
    NSDate *localDate = [dateNow dateByAddingTimeInterval:interval];
    NSLog(@"%@",localDate);

2.把当前时间转换成时间戳orm

_timeSp = (long)[dateNow timeIntervalSince1970];
    NSLog(@"timeSp:%ld",(long)_timeSp); //时间戳的值

3.把时间戳转换为时间string

NSDate *time = [NSDate dateWithTimeIntervalSinceNow:1464274800];
    NSLog(@"%@",time);

4.输出只有年月日   忽略时分秒it

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy年MM月dd日"];
    NSString *str = [formatter stringFromDate:date];
相关文章
相关标签/搜索