Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Samsung SmartTV get current time

How can I get current time for Samsung SmartTV app written on HTML, CSS and JavaScript?

The problem is in Javascript Date object. When I call new Date() on the web environment, I receive system Date value with current time. But when I instantiate date on SmartTV it returns incorrect result. I expected the same behavior as on the web. In TV settings time is set to be automatically determined.

Correct time returns only when I set time zone manually on first TV boot. I suppose it is bug of Samsung SmartTV platform.

like image 458
Andrei Avatar asked May 22 '14 07:05

Andrei


People also ask

Can my Samsung TV show the time?

There is no clock facility built into Samsung TVs. However, if you press INFO on your remote control when viewing a Freeview channel the current time will be displayed (along with details on the current programme).

How do I get the clock on my smart TV?

On the remote control, press the Quick settings button. Select Settings. Select Date & time. Select Clock display and then select On (always).


2 Answers

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.

like image 157
Andy E Avatar answered Dec 12 '22 19:12

Andy E


In most cases time on TV is correct, it is just in different time zone.

For example i have 2 devices near me at this moment, LG TV display date with GMT+3, and Samsung with GMT+1. Both devices display correct time.

If you need to display it with specific time zone, you can add time zone offset to date:

var date = new Date();
var offset = 4 * 3600000;//Moscow(GMT+4)
var userOffset = date.getTimezoneOffset() * 60000;
var fixedTime = new Date(date.getTime() + offset + userOffset);

If internal TV clock is not reliable, you can use web-services to get current time.

like image 34
Ivan Solntsev Avatar answered Dec 12 '22 17:12

Ivan Solntsev