需要在Objective-C中获得中心时间

需要在Objective-C中获得中心时间

问题描述:

我有需要获取当前时间(CST)的应用程序.我正在尝试使用以下代码,但NDate与GMT相同:

I have app where i need to get the current time (CST). I'm trying to use the following code but the NDate is the same as GMT:

NSDate* date = [NSDate date];
    NSLog(@"Time is %@", [date description]);

    [NSTimeZone setDefaultTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"CST"]];
    NSDate* nDate = [NSDate date];
    NSLog(@"Central time is%@", [nDate description])

除了时间本身没有时区之外,您还必须添加一个日历来设置与时区相关的日历,如我所描述的此处,您不应使用

Beside the fact that the time has not timezone itself, but you have to add a calendar to set it in relation to a time zone as I described here, you should not use a tz abbreviation as described here.