user663724
user663724

Reputation:

Javascript Split function

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 ??

Upvotes: 2

Views: 326

Answers (4)

kennebec
kennebec

Reputation: 104760

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 
*/

Upvotes: 0

sv_in
sv_in

Reputation: 14039

You can use Regular expressions:

For this: /[\s][A-Za-z0-9]+[\s][0-9]+/

jsFiddle

Upvotes: 0

Luke Dennis
Luke Dennis

Reputation: 14550

var date_split = date_string.split(" ");

var new_date_string = date_split[1]+" "+date_split[2]+" "+date_split[3];

Upvotes: 0

alex
alex

Reputation: 490173

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(' ');

jsFiddle.

Upvotes: 6

Related Questions