iOS标准时间与时间戳相互转换

来源:互联网 发布:源码网 编辑:程序博客网 时间:2024/05/04 18:20
  1. 时间转时间戳的方法:  
  2.     NSString *timeSp = [NSString stringWithFormat:@"%d", (long)[datenow timeIntervalSince1970]];  
  3.     NSLog(@"timeSp:%@",timeSp); //时间戳的值  
  4.  时间戳转时间的方法  
  5.     NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1296035591];  
  6.     NSLog(@"1296035591  = %@",confromTimesp);        
  7.     NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];  
  8.     NSLog(@"confromTimespStr =  %@",confromTimespStr);  

/////////////////////////////////////////////////////////////////////////////////

    //时间戳转成时间

    NSTimeInterval timeInterval = [@"1350359820.211" doubleValue];

    NSDate *date2 = [NSDate dateWithTimeIntervalSince1970:timeInterval];

    NSLog(@" date2 -------------------- %@",date2);



/////////////////////////////////////////////////////////////////////////////////

0 0
原创粉丝点击