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?
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With