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
JavaScript

Avatar of undefined
Last Comment
Bill Prew

8/22/2022 - Mon
SOLUTION
Gregg

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
hielo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck