iOS开发笔记之Timestamp时间戳与各地区实际时间格式的相互转换
来源:互联网 发布:游标卡尺的数据异常值 编辑:程序博客网 时间:2024/06/03 19:53
// 实际时间转为时间戳
- (NSString *)translateTimestampFormat:(NSString *)realtime {
NSString *template =@"yy/MM/dd HH:mm";
// 根据地区转换时间格式,注意某些国家时间格式中含有逗号
NSString *formatStr = [NSDateFormatter dateFormatFromTemplate:template options:0 locale:[NSLocale currentLocale]];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:formatStr];
NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
[formatter setTimeZone:timeZone];
NSDate *date = [formatter dateFromString:realtime];
NSTimeInterval time = [date timeIntervalSince1970];
return [NSString stringWithFormat:@"%lld", (longlong)time];
}
// 时间戳转为实际时间格式
- (NSString *)transformTime:(longlong)timestamp {
NSDate *date = [NSDate dateWithTimeIntervalSince1970:timestamp];
NSString *template =@"yy/MM/dd HH:mm";
NSString *formatStr = [NSDateFormatter dateFormatFromTemplate:template options:0 locale:[NSLocale currentLocale]];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:formatStr];
[formatter setTimeZone:[NSTimeZone systemTimeZone]];
NSString *time = [formatter stringFromDate:date];
return time;
}
- iOS开发笔记之Timestamp时间戳与各地区实际时间格式的相互转换
- js 时间格式与时间戳的相互转换
- 时间戳与时间格式的相互转换
- iOS时间与时间戳相互转换
- iOS时间格式的相互转换
- iOS开发中时间戳和时间的相互转换
- iOS开发之时间与时间戳的转换
- iOS中字符串时间与时间戳的相互转换
- iOS 开发 时间与时间戳的相互转化
- mysql 时间戳与日期格式的相互转换
- mysql 时间戳与日期格式的相互转换
- mysql 时间戳与日期格式的相互转换
- mysql 时间戳与日期格式的相互转换
- mysql 时间戳与日期格式的相互转换
- js时间戳与日期格式之间的相互转换
- 时间戳与时间的相互转换
- 时间与时间戳的相互转换
- 时间与时间戳的相互转换
- 洛谷 P3371 【模板】单源最短路径
- [乐意黎] 通过Apache代理访问NodeJS服务
- 栈的代码实现之数组方案
- 回顾大一·C语言编程4.2(2)
- vue+bootstrap响应是轮播绑数据(视频门户网站)
- iOS开发笔记之Timestamp时间戳与各地区实际时间格式的相互转换
- python如何装饰递归函数
- java的JDK安装好后运行cmd显示没有安装成功
- ros学习笔记-lesson1
- 基于java反射筛选List对于不同实体泛型的公共方法
- 第2次课改善深层神经网络:超参数优化、正则化以及优化
- 接入支付宝SDK遇到的坑
- Selenium php-webdrive元素等待
- Mac OS X系统 HomeBrew的安装和简单使用