Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Date/Time from server

Questions related to using nuBuilder Forte.
Post Reply
marc
Posts: 92
Joined: Mon May 14, 2018 3:26 pm

Date/Time from server

Unread post 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;

}
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Date/Time from server

Unread post 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.
Post Reply