首页 > 移动平台 > 详细

iOS 系统时间 转换为当前时区时间

时间:2016-05-09 12:31:51      阅读:297      评论:0      收藏:0      [点我收藏+]

- (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;

}

iOS 系统时间 转换为当前时区时间

原文:http://www.cnblogs.com/deneyZhao/p/5473411.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!