2

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
1

4 Answers 4

6

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.

answered May 30, 2011 at 5:30
Sign up to request clarification or add additional context in comments.

Comments

0
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

Comments

0

You can use Regular expressions:

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

jsFiddle

answered May 30, 2011 at 5:41

Comments

0

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.