If you are working with date and times then here are the best way to get dates and time with JS.
You can save a picture for quick reference
1. You can use the
toDateString(); method to get the current date with the day,
month and year as the string. Alternatively, you can also get the
getYear() to get the current date, month and year separately.
2. You can use the
toTimeString() method to get the current time of the
day as a string. Alternatively, you can use the
getMinutes( ) and
getSeconds() method to get the current hour, minute and second
of the day separately.
toTimeString() show the current date and
time without being aware of the locale. If you plan to format the date
and time shown to users based on their locale, you can use the
toLocaleTimeString() methods respectively.
4. If you ever decide that you want to show the universal time to all
your users irrespective of the timezone that they are in, you can use
day, month and year using the
getUTCYear() methods respectively.