Page 1 of 1

Date/Time from server

Posted: Thu May 07, 2020 7:02 am
by marc
There is a button, when clicked, the current date/time is written into a field. So far so good. My problem is now if a user has their computer clock off the wrong date/time is saved to the db.
I'm wondering if there's some way get the date/time form the server instead from the local clock?

Code: Select all

function dateTimeNow() { // e.g. "2020-05-07 20:01:46"

    var date = new Date();
    var aaaa = date.getFullYear();
    var gg = date.getDate();
    var mm = (date.getMonth() + 1);

    if (gg < 10)
        gg = "0" + gg;

    if (mm < 10)
        mm = "0" + mm;

    var cur_day = aaaa + "-" + mm + "-" + gg;

    var hours = date.getHours()
    var minutes = date.getMinutes()
    var seconds = date.getSeconds();

    if (hours < 10)
        hours = "0" + hours;

    if (minutes < 10)
        minutes = "0" + minutes;

    if (seconds < 10)
        seconds = "0" + seconds;

    return cur_day + " " + hours + ":" + minutes + ":" + seconds;

}

Re: Date/Time from server

Posted: Sun May 17, 2020 9:59 am
by kev1n
Hi marc,

Run a PHP procedure with nuRunPHPHidden() that retrieves the time from the SQL Server.

See this topic:
https://forums.nubuilder.cloud/viewtopic. ... time#p9842

use nuJavascriptCallback to pass the time to the client.