And*_*rei 5 samsung-smart-tv smart-tv smart-tv-alliance
如何获得使用HTML,CSS和JavaScript编写的Samsung SmartTV应用程序的当前时间?
问题出在Javascript Date对象中.当我new Date()在Web环境中调用时,我会收到当前时间的系统日期值.但是当我在SmartTV上实例化日期时,它会返回错误的结果.我期望与网络上的行为相同.在电视设置中,时间设置为自动确定.
只有在第一次电视启动时手动设置时区时,才能返回正确的时间.我想这是三星SmartTV平台的bug.
我有同样的问题。 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);
Run Code Online (Sandbox Code Playgroud)
new Date()现在可以在我的 2013 款三星智能电视上正常显示当前时间。但是,在将时间戳与当前时间进行比较时,您可能仍然会遇到问题。
| 归档时间: |
|
| 查看次数: |
4889 次 |
| 最近记录: |