iOS开发中时间格式的转化

来源:互联网 发布:maxdos网络克隆教程 编辑:程序博客网 时间:2024/05/17 08:12

一:将时间转化成时间戳
NSString *timeSp = [NSString stringWithFormat:@”%d”, (long)[localeDate timeIntervalSince1970]];

NSLog(@"timeSp:%@",timeSp); //时间戳的值

二:将获取的时间转化成当前时间
NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式

NSTimeZone *zone = [NSTimeZone systemTimeZone];NSInteger interval = [zone secondsFromGMTForDate:datenow];NSDate *localeDate = [datenow  dateByAddingTimeInterval: interval];NSLog(@"%@", localeDate);

三:把时间戳转化成时间的方法
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1363948516];
NSLog(@”1363948516 = %@”,confromTimesp);

0 0
原创粉丝点击