﻿function checkTime() {
    var now = new Date();
    if ($("#time").text() == '') {
        setServerDateTime();
    }
    if (now.getSeconds() < 1) {
        setServerDateTime();
    }
}

function setServerDateTime() {
    $.ajax({
        type: "POST",
        url: "/GetDateTime.ashx",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            $("#time").text(data.currTime + ' МСК');
            $("#date").text(data.currDate);
        }
    });
}

function updateDateTime() {
    setServerDateTime();
    setInterval(checkTime, 1000);
}

