ios 时间戳 NSString转NSDate转long

Bertha 。 2022-07-14 04:26 289阅读 0赞

1.问题

  1. NSString 格式的时间戳 ===》NSDate 时间戳 ===》long 毫秒的时间戳

2. code

  1. NSDateFormatter \*dateFormatter = \[\[NSDateFormatter alloc\]init\];
  2. \[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"\];
  3. NSDate \*logDate = \[dateFormatter dateFromString:@"**2016-11-27 16:14:49**"\];
  4. NSTimeInterval logDateInterval= \[logDate timeIntervalSince1970\];
  5. long logTime= logDateInterval\*1000;
  6. //默认是秒,毫秒 时间戳\*1000 ,想取得微秒 时间戳 \* 1000 \* 1000
  7. //long logTime= (long)\[logDatetimeIntervalSince1970\]; 要是这样,后台得到的是'1970-01-18 18:20:08'
  8. //ASIFormDataRequest POST 参数要求是对象,故long 转为NSNumber
  9. NSNumber \*logTimeNum = \[NSNumber numberWithLong:logTime\];
  10. \[request setPostValue:logTimeNum forKey:@"logTime"\];

发表评论

表情:
评论列表 (有 0 条评论,289人围观)

还没有评论,来说两句吧...

相关阅读