I am getting Date in this format (Fri May 13 2011 19:59:09 GMT 0530 (India Standard Time) )
Please tell me how can i use Javascript split function , so that i can get only May 13 2011 ??
asked May 30, 2011 at 5:29
user663724
-
possibility duplicate stackoverflow.com/q/3014740/668970developer– developer2011年05月30日 05:36:18 +00:00Commented May 30, 2011 at 5:36
4 Answers 4
You could split() using space as the delimiter, slice() the required elements and then join() again with a space.
str = str.split(' ').slice(1, 4).join(' ');
answered May 30, 2011 at 5:30
alex
492k205 gold badges891 silver badges992 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
var date_split = date_string.split(" ");
var new_date_string = date_split[1]+" "+date_split[2]+" "+date_split[3];
answered May 30, 2011 at 5:30
Luke Dennis
14.6k17 gold badges60 silver badges70 bronze badges
Comments
answered May 30, 2011 at 5:41
sv_in
14k9 gold badges38 silver badges55 bronze badges
Comments
You can make arrays of the string and manipulate the array members back to a string, but it is simpler to just cut the existing string at the space before the hours.
var D='Fri May 13 2011 19:59:09 GMT 0530 (India Standard Time)';
alert(D.substring(0, D.search(/\s+\d{2}\:/))
/* returned value: (String)
Fri May 13 2011
*/
answered May 30, 2011 at 5:41
kennebec
105k32 gold badges109 silver badges127 bronze badges
Comments
lang-js