EnexoOnoma
EnexoOnoma

Reputation: 8836

How to get server's time and port it into this JavaScript function?

I have this jQuery script but instead of getting the time from my computer, how can I get the time on page arrival using the server's time using PHP? No counting or changing in time is needed.

$(function () {
  var now = new Date();

$('#date').scroller({
    preset: 'datetime',
    minDate: new Date(now.getFullYear(), now.getMonth(), now.getDate()),
    theme: 'android-ics',
    display: 'inline',
    mode: 'scroller',
    dateOrder: 'ddM',
    dateFormat: 'yy-mm-dd',
    timeFormat: 'HH:ii:ss',
    timeWheels: 'HHii',
    stepMinute: 10,
    rows: 3

   }).scroller('setDate', now, true);
});

Upvotes: 1

Views: 185

Answers (2)

Mike Brant
Mike Brant

Reputation: 71384

Just dynamically insert the time value from PHP into the output javascript.

var serverTime = <?php echo time(); ?>

Obviously you can format the time however you want, this example just unix timestamp.

Then use in you jQuery like this:

             $('#date').scroller({
                preset: 'datetime',
                minDate: serverTime,
                theme: 'android-ics',
                display: 'inline',
                mode: 'scroller',
                dateOrder: 'ddM',
                dateFormat: 'yy-mm-dd',
                timeFormat: 'HH:ii:ss',
                timeWheels: 'HHii',
                stepMinute: 10,
                rows: 3

            }).scroller('setDate', now, true);

Upvotes: 1

Mooseman
Mooseman

Reputation: 18891

Assuming the jQuery is inline in your PHP page, you can replace the new Date(... with <?php echo date(Y:m:d); ?>

You could also insert a function for an ajax request to get the time from your server.

Upvotes: 0

Related Questions