Timestamp Formatting For Hidden Field On Form

Discussion in 'JavaScript' started by tapupartforpres, Dec 22, 2021.

  1. #1
    Hello Everyone,

    I had a quick question I know you Javascript junkies will know. I just can't seem to figure this out.

    Below I have some JavaScript, that is working and populating the field. But this is what it is passing "Wed Dec 22 2021 13:44:05 GMT-0500 (Eastern Standard Time)". This needs to be formatted as such, with a space in between: MM/DD/YYYY HH:MM:SS (for Google Ad tracking).

    Any help would be great. Below is the Javascript I am using, but it is not formatted properly. Thanks.

    <script>
    // Change the word Date_Submitted in the following line to the name of your hidden field label.
    // It has to match exact label, including capitals, underscore, etc...
    var inpElm = document.getElementById('Conversion_Time');                                    
    var d = new Date();
    var pD = d;
    window.setTimeout(sD, 5000);
    window.setInterval(sD, 30000);
    function sD(){
    inpElm.value = d;
    }
    sD();
    </script>
    Code (JavaScript):

     
    tapupartforpres, Dec 22, 2021 IP