Link to home
Start Free TrialLog in
Avatar of tmajor99
tmajor99

asked on

Javascript to get date & time without chars and spaces

I need a javascript that will get the current date time and then strip off all spaces and chars.  

For example;

Fri 01 22 2016 20:09:23 GMT-0500 (Eastern Standard Time)

Remove all spaces and chars:  01222016200923
SOLUTION
Avatar of Gregg
Gregg
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bill Prew
Bill Prew

If you do want to do it in just native JavaScript, then here is a straight forward (not overly clever) approach.  A couple of functions that then take a date and format as you wanted.

var d = new Date()
alert(fmtdate(d))

function fmtdate(d) {
    return d.getFullYear()+zpad2(d.getMonth()+1)+zpad2(d.getDate())+zpad2(d.getHours())+zpad2(d.getMinutes())+zpad2(d.getSeconds())
}

function zpad2(n) {
    if (n<10) { n = ("0"+n); }
    return n;
}

Open in new window

~bp