Reputation: 6762
I am using jquery/javascript and trying to convert date format to date with date+hours minute seconds. I tried with new Date(myFormatDate) but it gave me complete date including timezone. Is substring of new Date() is only option to get to my format?
From Format I am trying to convert
"2018-05-17T00:55:46"
To Format I am trying to achieve
2018-05-01 23:17:32.00
Upvotes: 0
Views: 74
Reputation: 130
Use an additional library like moment.js (https://momentjs.com/)
Following are couple of examples
moment().format('MMMM Do YYYY, h:mm:ss a'); // May 23rd 2018, 8:41:58 am
moment().format('dddd'); // Wednesday
moment().format("MMM Do YY"); // May 23rd 18
Upvotes: 1
Reputation: 31
I hope this function will help you
var d = new Date();
function FormatDate(DateToConvert){
return DateToConvert.getFullYear() + '-' + (DateToConvert.getMonth()+ 1) + '-' + DateToConvert.getDate() + " " + DateToConvert.getHours() + ":" + DateToConvert.getMinutes() + ":" + DateToConvert.getSeconds() + ':' + DateToConvert.getMilliseconds();}
console.log(FormatDate(d));
Upvotes: 1
Reputation: 67
I think this is the best way for you if want this specific case:
var someDate = new Date("2018-05-17T00:55:46");
var formatted = someDate.toISOString().slice(0,10) + " " + someDate.toISOString().slice(11,22);
Upvotes: 1