Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am having a string like below and i want to cut out the T with the time from it like below:

var string = '2021-05-10T08:00,2021-05-11T08:00,2021-05-12T08:00';

My new string should look like this:

var new_string = '2021-05-10,2021-05-11,2021-05-12';

How can i do that?

I tried with .replace function but the problem is that the time is not always 08:00

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
173 views
Welcome To Ask or Share your Answers For Others

1 Answer

Break it into an array and process each chunk. map is a good function for this

 var string = '2021-05-10T08:00,2021-05-11T08:00,2021-05-12T08:00';
    var newstring = string.split(",").map(el => el.split('T')[0]).join(",");
    console.log(newstring);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...