What is the best way to convert YYYY-MM-DDTHH:mm:ss±hh:mm(string) to YYYYMMDDHHmmss(string) using regex or any other way?
For eg: 2020-02-27T01:23:44-05:30 to 20200227012344
Can someone help me here?
What is the best way to convert YYYY-MM-DDTHH:mm:ss±hh:mm(string) to YYYYMMDDHHmmss(string) using regex or any other way?
For eg: 2020-02-27T01:23:44-05:30 to 20200227012344
Can someone help me here?
Fastest way for me. Relies on constant size of input string.
const input = "2020-02-27T01:23:44-05:30"
const input2 = "2020-02-27T01:23:44+05:30"
const testOutput ="20200227012344"
const transformTime = time => time
.split('-')
.join('')
.split('+')
.join('')
.split(':')
.join('')
.split('T')
.join('')
.substring(0, 14)
console.log(transformTime(input) === testOutput)
console.log(transformTime(input2) === testOutput)
You could try this regex
(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\+(\d{2}):(\d{2})