-1
function getServerDateTime()
{

    <?php
    $timezone = 'America/Chicago';
    $timestamp = time();
    $dt = new DateTime("now", new DateTimeZone($timezone));
    $dt->setTimestamp($timestamp);
    $serverNow = $dt->format('m.d.Y H:i:s');
    ?>
    
    let phpDate = "<?=$serverNow?>";
    return new Date(phpDate);
}

function test()
{
    let d = getServerDateTime()
}

I am trying to get the server date. It work on chrome but it won't even load on firefox.

Futterkiste
  • 51
  • 1
  • 6
  • https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming is worth a read. Your code is going to give you the server time when the page was sent to the browser, not when the JS function is called. – Quentin May 24 '22 at 10:36
  • 2
    And as the duplicate question alludes, change `'m.d.Y H:i:s'` to a format that `new Date()` is expected to be able to parse instead of hitting the "Not a standard data format, it is up to the browser to decide what to do with it" fallback position. – Quentin May 24 '22 at 10:37

0 Answers0