美文网首页
时间戳相关

时间戳相关

作者: 我一不小心就 | 来源:发表于2019-04-05 11:20 被阅读0次
     // 获取时间戳,并将时间戳转为北京时间
     NSTimeInterval duration = [[NSDate date] timeIntervalSince1970];
       NSString *timeString = [NSString stringWithFormat:@"%f", duration];
       NSLog(@"====>返回URL时间戳 =>%@",timeString);
       
       NSTimeInterval time=[timeString doubleValue] ;//传入的时间戳str如果是精确到毫秒的记得要/1000
       NSDate *detailDate=[NSDate dateWithTimeIntervalSince1970:time];
       NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; //实例化一个NSDateFormatter对象
       //设定时间格式,这里可以设置成自己需要的格式
       [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss SS"];
       NSString *currentDateStr = [dateFormatter stringFromDate: detailDate];
       NSLog(@"====>返回URL时间戳 => ===>%@",currentDateStr);

相关文章

网友评论

      本文标题:时间戳相关

      本文链接:https://www.haomeiwen.com/subject/pguhiqtx.html