gpt4 book ai didi

android - Titanium - 我如何才能始终获得特定时区并仅获得时间?

转载 作者:行者123 更新时间:2023-11-29 03:43:10 24 4
gpt4 key购买 nike

我试图始终获取特定时区的特定时间

例如:圣保罗(-3)

我尝试过在 stackoverflow 上搜索到的这段代码:

// function to calculate local time
// in a different city
// given the city's UTC offset
function calcTime(city, offset) {

// create Date object for current location
d = new Date();

// convert to msec
// add local time zone offset
// get UTC time in msec
utc = d.getTime() + (d.getTimezoneOffset() * 60000);

// create new Date object for different city
// using supplied offset
nd = new Date(utc + (3600000*offset));

// return time as a string
return "The local time in " + city + " is " + nd.toLocaleString();

}

// get Sao Paulo time
Ti.API.info(calcTime('Sao Paulo', '-3'));

在我的 Ti.API.info() 上,我得到以下响应:圣保罗本地时间是 2013 年 8 月 6 日下午 3:31:52 GMT-03: 00...有办法只得到 3:31:52 吗?此外...正如这个函数所说...它始终获得本地时间,并且它们显示该时区的时间...但是有人知道我如何才能始终获得圣保罗的时间而不给出本地时间?因此,如果用户更改手机上的时间,则不会更改圣保罗的时间。

谢谢

最佳答案

使用 momentjs 特别是时刻时区

http://momentjs.com/timezone/docs/

如果您使用 Alloy,则默认包含 momentjs,如果没有,则需要下载该库。

关于android - Titanium - 我如何才能始终获得特定时区并仅获得时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18085946/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com