I’m trying to slice a specific part of a string, but could not find any information on it.
I want to remove the first set of 00s and : from 10:00:00 AM without removing the AM so 10:00AM.
I could only find out how to slice from the back or front using -,+ symbols but not from the middle.
EDIT – Only want var ‘dt’ sliced not looking for a solution for other time values.
var dt = 10:00:00 AM
const result1 = dt.toLocaleString().slice(Number Here);
console.log(result1)
//want the result to be 10:00 AM
Thanks!
>Solution :
You can do the following:
const dt = '10:00:00 AM';
const result1 = dt.slice(0, 3) + dt.slice(6);
console.log(result1);