Draw a date after converting it to a string

I have a date in milliseconds that I convert to a readable date. Then I hide it until the line so that I can break it and break it to use the parts I need. The problem is that when I break this space, it breaks each character by itself and does not break it where there is a space. Can someone explain why and what I am doing wrong?

here is my code:

var formattedDate = new Date(somedateMS);

var formattedDateSplit = formattedDate.toString();

formattedDateSplit.split(" ");

console.log(formattedDateSplit);  // Mon May 18 2015 18:35:27 GMT-0400 (Eastern Daylight Time)
console.log(formattedDateSplit[0]); // M
console.log(formattedDateSplit[1]); // o
console.log(formattedDateSplit[2]); // n
console.log(formattedDateSplit[3]); // [space]
console.log(formattedDateSplit[4]); // M
console.log(formattedDateSplit[5]); // a
console.log(formattedDateSplit[6]); // y

How can I divide it so that I can get rid of the day of the week, and just so that on May 18, 2015 18:35:27 into 4 separate values? (May 18, 2015 6:35:27 PM)?

I have done this before and am not sure why this time he breaks it down by character.

Thank!

+4
source share
1 answer

formattedDateSplit Date, unsplit:

var formattedDateSplit = formattedDate.toString();

, , , :

formattedSplit.split(" ");

; , , :

formattedDateSplit = formattedDateSplit.split(" ");

, , . .split() , -; .

+7

All Articles