iOS-获取时间戳

 时间戳(timestamp),通常是一个字符序列,唯一地标识某一刻的时间。

时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。

-(NSString *) getTimeStampWithOffsetTime:(NSInteger)offsetTime {
    NSDate* date = [NSDate dateWithTimeIntervalSinceNow:offsetTime];//获取当前时间 offsetTime 秒后的时间
    NSTimeInterval time =[date timeIntervalSince1970];//默认单位是秒,*1000单位为毫秒
    NSString *timeString = [NSString stringWithFormat:@"%.0f", time];
    return timeString;
}

 打印如下:

时间戳=1539924585

 时间戳在线转换工具

猜你喜欢

转载自blog.csdn.net/qq_36557133/article/details/83180813