Native JavaScript provides Date.toString()
to convert a Date to a string like the one you showed, and also Date.toLocaleString()
to convert a Date into a string according to configurations of the user's client.
For me, the best way to convert Dates to a readable string is to manually get the parts of the Date object you want to display. You may use date.getFullYear
, date.getMonth
, date.getDay
or date.getDate
. The main problem with this is that you get numbers for both Months and Dates, and you have to map the number to a string.
Note: Months start at 0, wich means Jannuray = 0, so for a classical mm/dd/aaaa format you need to add 1 to the value returned by date.getMonth
.
A quick example on how to get a mm/dd/aaaa format out of a Date object:
var dateToString = (date.getMonth() + 1) + '/' + date.getDay() + '/' + date.getFullYear();
Another solution is to use a library such as datejs which makes it easy and simple.