Ios 从UTC时间获取设备时间/本地时间(单位:秒)

Ios 从UTC时间获取设备时间/本地时间(单位:秒),ios,datetime,titanium,titanium-mobile,Ios,Datetime,Titanium,Titanium Mobile,我正在做钛的应用。 我想用当地时间。 我的问题是,当我使用: var currentDateTime = new Date(); 它显示UTC时间 是否仍有获取当前本地时间或设备时间的方法?我使用getTimezoneOffset函数解决了这个问题 我编写了一个方法,将UTC时间作为参数,并返回本地时间 //Function Processes the passed UTC time and returns the current device time. function changeUTC

我正在做钛的应用。 我想用当地时间。 我的问题是,当我使用:

var currentDateTime = new Date();
它显示UTC时间


是否仍有获取当前本地时间或设备时间的方法?

我使用
getTimezoneOffset
函数解决了这个问题

我编写了一个方法,将UTC时间作为参数,并返回本地时间

//Function Processes the passed UTC time and returns the current device time.
function changeUTCToLocal(utcTime)
{
    var offset = utcTime.getTimezoneOffset();
    var localTime = utcTime + offset;
    return localTime;
}

我使用
getTimezoneOffset
函数修复了这个问题

我编写了一个方法,将UTC时间作为参数,并返回本地时间

//Function Processes the passed UTC time and returns the current device time.
function changeUTCToLocal(utcTime)
{
    var offset = utcTime.getTimezoneOffset();
    var localTime = utcTime + offset;
    return localTime;
}

从格林尼治时间获取时间间隔以及当前本地时间和格林尼治时间的偏移量,将它们相加,从本地时间获取实时时间间隔:

假设时间间隔为距GMT的NSInteger毫秒时间, 使用以下命令获取偏移量

  NSInteger millisecondsFromGMT = 1000 * [[NSTimeZone localTimeZone] secondsFromGMT];
现在将这两个值相加以获得实时间隔

NSInteger realTimeInterval = timeInterval + millisecondsFromGMT ;

从格林尼治时间获取时间间隔以及当前本地时间和格林尼治时间的偏移量,将它们相加,从本地时间获取实时时间间隔:

假设时间间隔为距GMT的NSInteger毫秒时间, 使用以下命令获取偏移量

  NSInteger millisecondsFromGMT = 1000 * [[NSTimeZone localTimeZone] secondsFromGMT];
现在将这两个值相加以获得实时间隔

NSInteger realTimeInterval = timeInterval + millisecondsFromGMT ;

我认为moment.js也可以解决这个问题

我认为moment.js也可以解决这个问题

我已经提到我正在开发基于钛的iOS应用程序。:)我已经提到我正在开发基于钛的iOS应用程序