I have a Date Time string 2018-08-10T14:33:44.000Z
. I want to convert it into, 2018-08-10 14:33:44
by using Javascript.
I can convert it to UTC or Local time. But, I am looking for that specific format only.
I have a Date Time string 2018-08-10T14:33:44.000Z
. I want to convert it into, 2018-08-10 14:33:44
by using Javascript.
I can convert it to UTC or Local time. But, I am looking for that specific format only.
Luckily, since your input is a datetime string, you can transform the string easily with a regular expression, no need to mess with date manipulation at all. Match the T
, capture the following time string in a group, then replace the T and everything that follows with a space followed by that group:
const input = '2018-08-10T14:33:44.000Z'
console.log(
input.replace(/T((\d{2}:){2}\d\d).+/, ' $1')
);
Use the 'moment' javascript library. Then you can do something like:
moment(new Date()).format("YYYY-MM-DD HH:mm:ss")