gpt4 book ai didi

samsung-smart-tv - 三星智能电视获取当前时间

转载 作者:行者123 更新时间:2023-12-04 18:07:27 25 4
gpt4 key购买 nike

如何获取使用 HTML、CSS 和 JavaScript 编写的 Samsung SmartTV 应用程序的当前时间?

问题出在 Javascript Date目的。当我打电话时new Date()在网络环境中,我收到系统日期值和当前时间。但是当我在 SmartTV 上实例化日期时,它返回错误的结果。我期望与网络上的行为相同。在电视设置中,时间设置为自动确定。

只有当我在第一次电视启动时手动设置时区时才会返回正确的时间。我想这是三星 SmartTV 平台的错误。

最佳答案

我有同样的问题。 new Date()在三星智能电视上,不会根据当前设置获取时间,而是获取底层系统时间。它也总是返回一个 UTC 时间戳。

幸运的是,有一个 API 函数, GetEpochTime() ,这允许您(某种程度上)修复它。

这是我在三星平台上使用的代码:

(function (OldDate) {
// Get a reference to Samsung's TIME API
var time = document.createElement('object');
time.setAttribute('classid', 'clsid:SAMSUNG-INFOLINK-TIME');
document.body.appendChild(time);

// Replace the existing Date() constructor
window.Date = function (a, b, c, d, e, f, g) {
switch (arguments.length) {
case 0:
return new OldDate(time.GetEpochTime() * 1000);

case 1: return new OldDate(a);
case 2: return new OldDate(a, b);
case 3: return new OldDate(a, b, c);
case 4: return new OldDate(a, b, c, d);
case 5: return new OldDate(a, b, c, d, e);
case 6: return new OldDate(a, b, c, d, e, f);
case 7: return new OldDate(a, b, c, d, e, f, g);
}
};

// Copy static function properties
Date.now = function () { return time.GetEpochTime() * 1000; };
Date.UTC = OldDate.UTC;
Date.parse = OldDate.parse;
})(Date);
new Date()现在可以很好地在我的 2013 三星智能电视上显示当前时间。但是,将时间戳与当前时间进行比较时,您可能仍然会遇到问题。

关于samsung-smart-tv - 三星智能电视获取当前时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23800177/

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