需要在Objective-C中获得中心时间 [英] need to get central time in objective-c

查看:93
本文介绍了需要在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.

这篇关于需要在Objective-C中获得中心时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆