将其他时区转换当前系统时区
来源:互联网 发布:音乐动画相册制作软件 编辑:程序博客网 时间:2024/06/05 22:56
//将其他时区转换当前系统时区
- (NSDate *)getNowDateFromatAnDate:(NSDate *)anyDate
{
//设置源日期时区
NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];//或GMT
//设置转换后的目标日期时区
NSTimeZone* destinationTimeZone = [NSTimeZone localTimeZone];
//得到源日期与世界标准时间的偏移量
NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:anyDate];
//目标日期与本地时区的偏移量
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:anyDate];
//得到时间偏移量的差值
NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
//转为现在时间
NSDate* destinationDateNow = [[NSDate alloc] initWithTimeInterval:interval sinceDate:anyDate];
return destinationDateNow;
}
- (NSDate *)getNowDateFromatAnDate:(NSDate *)anyDate
{
//设置源日期时区
NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];//或GMT
//设置转换后的目标日期时区
NSTimeZone* destinationTimeZone = [NSTimeZone localTimeZone];
//得到源日期与世界标准时间的偏移量
NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:anyDate];
//目标日期与本地时区的偏移量
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:anyDate];
//得到时间偏移量的差值
NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
//转为现在时间
NSDate* destinationDateNow = [[NSDate alloc] initWithTimeInterval:interval sinceDate:anyDate];
return destinationDateNow;
}
0 0
- 将其他时区转换当前系统时区
- 转换当前的时区到北京时区
- iPhone中将特定时区的某个时间与当前所在时区或其他时区时间相互转换
- [iOS 转换东八区] 将手机当前时区全都转为东八区
- iOS 系统时间 转换为当前时区时间
- Qt获取当前系统时区
- [iOS]获得当前系统时间(当前时区)
- IOS 获得当前系统时间(当前时区)
- 时区转换
- 时区转换
- 时区转换
- JavaScript获取当前时区 时间转换
- 获取当前系统北京时区的时间
- Linux下修改系统当前时区
- linux c 获取系统当前时区
- 时区
- 时区
- 时区
- 索引的创建及使用(sqlserver 2000)
- PrimeFaces
- UVA 1395 Slim Span
- Cocos2d-x 3.0final 终结者系列教程17-屏幕截图后跳转到另外场景
- 点滴记录——Ubuntu 14.04中安装Sublime Text 3并使用SublimeClang插件
- 将其他时区转换当前系统时区
- ant
- 响应性原则之三:用户界面是实时接口
- 原子操作(atomic operation)
- dom对象和Jquery对象搞混了,概念不清楚
- 定制Linux系统原理
- MAC COCOA一个简单的多线程程序
- shell 加密
- show engine innodb status发现deadlock