iOS获取当前时区

来源:互联网 发布:公共服务 网络 编辑:程序博客网 时间:2024/05/20 21:21

//在程序中,有时候需要获得当前时区,比如北京是在东8区,

//ios 貌似没有提供直接获取时区的方法,反正我是没看到可怜

//所以我们只能获取当前所在时区相对0时区的偏移秒数

//即使用secondsFromGMTForDate方法获取偏移秒数

    NSTimeZone* destinationTimeZone = [NSTimeZonelocalTimeZone] ;///获取当前时区信息

   NSInteger sourceGMTOffset = [destinationTimeZonesecondsFromGMTForDate:[NSDatedate]];///获取偏移秒数

   NSLog(@"offset = %zd",sourceGMTOffset/3600);///除以3600即可获取小时数,即为当前时区

0 0