Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
52
rated 0 times [  57] [ 5]  / answers: 1 / hits: 15312  / 7 Years ago, mon, january 22, 2018, 12:00:00

i wanted to ask if someone knows how to remove the Day Name from the following example,the alert returns Sat Feb 29 2020, im not using Moment.js only Jquery because i only need to be able to handle the date in the format that is written below as code.



var mydate = new Date('29 Feb 2020');
alert(mydate.toDateString());


Thank you for reading this question and hope i make clear what my problem is


More From » jquery

 Answers
18

The Date#toDateString method would result always returns in that particular format.



So either you need to generate using other methods available or you can remove using several ways,





1. Using String#split, Array#slice and Array#join





var mydate = new Date('29 Feb 2020');
// split based on whitespace, then get except the first element
// and then join again
alert(mydate.toDateString().split(' ').slice(1).join(' '));







2. Using String#replace





var mydate = new Date('29 Feb 2020');
// replace first nonspace combination along with whitespace
alert(mydate.toDateString().replace(/^S+s/,''));







3. Using String#indexOf and String#substr


var mydate = new Date('29 Feb 2020');
// get index of first whitespace
var str = mydate.toDateString();
// get substring
alert(str.substr(str.indexOf(' ') + 1));




[#55400] Thursday, January 18, 2018, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brittanye

Total Points: 263
Total Questions: 94
Total Answers: 115

Location: Burkina Faso
Member since Thu, Dec 23, 2021
3 Years ago
;