在Objective-C中,可以使用NSDate和NSDateFormatter来获取当前的北京时间。下面是一个示例代码:

// 创建一个NSDateFormatter对象
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

// 设置时区为北京时间
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Shanghai"]];

// 设置日期格式
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

// 获取当前的北京时间
NSString *beijingTime = [dateFormatter stringFromDate:[NSDate date]];

NSLog(@"当前的北京时间:%@", beijingTime);

运行以上代码,将会输出当前的北京时间。请确保你的设备的时区设置正确,以便正确获取北京时间。

object-c获取北京时间

原文地址: http://www.cveoy.top/t/topic/iDbM 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录