Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
18
rated 0 times [  23] [ 5]  / answers: 1 / hits: 42494  / 10 Years ago, tue, july 15, 2014, 12:00:00

I'm working with a string of data in this format: mm-dd-yy. I convert this to a Date object in this way:



var dateData, dateObject, dateReadable, dateSplit, year, month, day;

dateData = 07-21-14; //For example

dateSplit = dateData.split('-');

month = dateSplit[0] - 1;
day = dateSplit[1];
year = 20 + dateSplit[2];

dateObject = new Date(year, month, day);

dateReadable = dateObject.toUTCString(); //Returns Mon, 21 Jul 2014 04:00:00 GMT


I would like to return the date (Mon, 21 Jul 2014) without the time (04:00:00 GMT). Is there a different method that will do so? Or a way of calling .toUTCString() to return the date without the time?


More From » date

 Answers
21

I believe you want .toDateString() or .toLocaleDateString()



http://www.w3schools.com/jsref/jsref_todatestring.asp



In fact, you should also look at Date.parse():



var dateData, dateObject, dateReadable;

dateData = 07-21-14; //For example

dateObject = new Date(Date.parse(dateData));

dateReadable = dateObject.toDateString();

[#70202] Friday, July 11, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
clifford

Total Points: 86
Total Questions: 114
Total Answers: 111

Location: Wales
Member since Mon, May 17, 2021
3 Years ago
;