ios 时间戳 当前时间 相互转化

来源:互联网 发布:游戏的网络销售怎么样 编辑:程序博客网 时间:2024/05/17 22:51

//一、将当前事件转化成时间戳
   NSDate *datenow     = [NSDate date];   NSString *timeSp    = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];   UInt32 timeStamp    = [timeSp intValue];

二、把获取的时间转化为当前时间
   NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式   NSTimeZone *zone = [NSTimeZone systemTimeZone];   NSInteger interval = [zone secondsFromGMTForDate:datenow];   NSDate *localeDate = [datenow  dateByAddingTimeInterval: interval];   NSLog(@"%@", localeDate);

3、把时间戳转化为时间的方法    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1363948516];    NSLog(@"1363948516  = %@",confromTimesp);