As with all other reference types there are a few methods that are naturally inherited by the Date type. These are: toLocaleString(), toString() and valueOf().
The representation of dates, when applying toLocaleString() and toString() methods heavily depends on the browsers used, especially the old ones.
The valueOf() method does not return a string as usually, but rather returns numbers; that is a reasonable aspect considering that the dates are converted to milliseconds by default.
Date formatting methods
Other methods that might be considered as basic are date-formatting methods. These are:
- toDateString(); Returns day of the week, month, day of the month and year.
- toTimeString(); Returns hours, minutes, seconds and time zone.
- toLocaleDateString(); Returns day of the week, month, day of the month and year in locale format.
- toLocaleTimeString(); Returns hours, minutes, seconds and time zone in locale format.
- toUTCString(); Returns the UTC date.
As with other methods above, the output of those as well depends on the locale settings and the browser specific implementation.
Example
Example of a basic conversions of a JavaScript Date type to a string:
Comments
No comments have been made yet.
Please login to leave a comment. Login now