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

GG.
  • 21,083
  • 14
  • 84
  • 130
Swapnil Yeole
  • 406
  • 3
  • 12
  • 26
  • This may help you? https://stackoverflow.com/questions/15141762/how-to-initialize-a-javascript-date-to-a-particular-time-zone https://stackoverflow.com/questions/439630/create-a-date-with-a-set-timezone-without-using-a-string-representation/439871#439871 – Lak Jan 24 '19 at 06:18
  • "*How to format a date*" has been asked many, many times before. – RobG Jan 24 '19 at 07:11

2 Answers2

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/

sjdm
  • 591
  • 4
  • 10
-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');
sanj singh
  • 59
  • 1
  • 3