I had the same problem. new Date()
on Samsung Smart TVs doesn't get the time according to the current setting, but instead gets the underlying system time. It always returns a UTC timestamp, too.
Fortunately, there's an API function, GetEpochTime()
, that allows you to (sort of) fix it.
Here's the code I'm using on Samsung platforms:
(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()
now works fine for displaying the current time on my 2013 Samsung Smart TV. You might still have problems when comparing timestamps to the current time, however.