We help IT Professionals succeed at work.

Need help with javascript date format

dave doyle
dave doyle asked
on
Need help getting this JavaScript to format with different date options like mm/dd/yyyy , mm/dd/yyyy 00:00 etc.

<%@ language="VBScript" %>
<!DOCTYPE html>
<html>
        <head>
        <script language='Javascript' runat='server'>

            function jsGetPastTimeCurrent(minutes) {
                var d = new Date();
                var past = new Date();
                past.setTime(d.getTime() + (minutes*60000));
                var utcString = past.toUTCString();
                var tz = utcString.indexOf("UTC");
                if (tz > 0) {
                    utcString = utcString.substring(0, tz) + "CT";
                }
                return utcString;
            }
        </script>
<% newDate=jsGetPastTimeCurrent(-360)%>
        <title>Timestamp</title>
    </head>
    <body>
    <p>
    <h2><%= newDate %> </h2>
    </p>
    </body>
</html>
Comment
Watch Question

All-around developer
Commented:
To be honest, the preeminent JavaScript date handling library is Moment.js. I'd suggest using it:
https://momentjs.com/

Author

Commented:
I've seen that . My web server is UTC but I need central time . Do you think it would work?
Eddie ShipmanAll-around developer

Commented:
Yes, it can convert the time zones as well.

Author

Commented:
Thank you . I'll give it a try.