2

I want datetime in custom format as per below.

2019-01-24T05:52:29:420 +0000 GMT+0000

but when I try do it using below syntax I did not work.

var currentdate = new Date(); 
alert(currentdate);

Any help? Thanks

2

2 Answers 2

0

Look into Moment.js, you can format JS dates with this quite easily.

e.g:

moment().format('MMMM Do YYYY, h:mm:ss a'); // January 24th 2019, 5:13:29 pm
moment().format('dddd');                    // Thursday

in your case:

moment(currentdate).format('the format you would like');

https://momentjs.com/

Sign up to request clarification or add additional context in comments.

3 Comments

I want output in plain javascript.
You don't want to use any libraries? and why?
I dont want to use any library.I am working in angular application
-1

its very simple you just have to do currentdate.toISOString() which will return "2019-01-24T06:19:19.975Z", now its simple just remove last char from string and concat the other string part in it.

var currentdate = new Date().toISOString();

alert(currentdate.substr(0, currentdate.length-1)+' +0000 GMT+0000');

1 Comment

This above is the correct answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.