我正在开发一个基于云的应用程序,它为世界各地的用户广泛处理日期和时间值。
考虑一个场景,在 JavaScript 中,我的机器在印度 (GMT+05:30),我必须显示在加利福尼亚时区 (GMT-08:00) 运行的时钟。
在这种情况下,我必须获得一个新的日期对象,
let india_date = new Date()
添加它的时区偏移值,
let uts_ms = india_date.getTime() + india_date.getTimezoneOffset()
添加加利福尼亚的时区偏移值,
let california_ms = utc_ms + getCaliforniaTimezoneOffsetMS()
最后是日期对象。
let california_date: Date = new Date(california_ms)
有没有办法直接处理这些类型的时区而不必一次又一次地转换值?
我有一个管理特定对话框的单独对象。考虑以下代码。由于很容易想象函数的作用,因此我无法访问该类的实例。我尝试使用传统that = this
方法。
export class Whatever implements OnInit {
that = this;
dialog = {
data:{},
open:function() {
//way to access 'that' variable
},
close:function() {},
toggle:function() {}
}
//other declarations and functions
}
Run Code Online (Sandbox Code Playgroud)
当我的应用程序扩展时,此服务中有太多功能。因此,我试图将这些功能中的一些整合到对象中,这将使代码更清晰。
另外,如果有更好的方法,我也想知道。谢谢。