0

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.

1

2 Answers 2

1

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')
);

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

Comments

1

Use the 'moment' javascript library. Then you can do something like:

moment(new Date()).format("YYYY-MM-DD HH:mm:ss")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.