0

I just wanted to now if there is a efficient way to convert DateTime String to a Specific Pattern in Nodejs.

Example:

I will receive a string StartDateTime = "2019-10-17 09:00:00" and i wanted to converto to two variables. The output spected will be like:

StartDate = "2019-10-17"
StartTime = "09%3A00%3A00"

Any ideas?

1
  • 1
    const [StartDate, StartTime] = StartDateTime.split(' '); Commented Oct 17, 2019 at 14:26

1 Answer 1

2

You could split at the space and use encodeURIComponent on the resulting array:

const startDateTime = "2019-10-17 09:00:00"
const [StartDate, StartTime] = startDateTime.split(' ').map(encodeURIComponent);

console.log(StartDate)
console.log(StartTime)

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

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.