How Important it is to Format Date in JavaScript

Guest Posts Paolo Nikko Nuñal

Formatting date's have been a common problem by many web developers most especially if they want a specific order or format that they wish to have on their forms. Luckily, the Date() object is a datatype built into the JavaScript language. To create a date you can use the keyword "new" followed by the Date() datatype.

Once a Data object is created, you can do a number of methods in order to operate. Most of these methods include year, month, day, hour, minute, second and millisecond fields of the object. You can also use UTC or GTM time.

Syntax:

new Date()
new Date([millisecond])
new Date([dateString])
new Date([year],[month],[date][,[hour],[minute],[second],millisecond])

MILLISECONDS - returns the milliseconds.

DATESTRING - returns a one string arguments.

YEAR - returns integer value of the year.

MONTH - returns integer value of the month.

DATE - returns the integer value of the month.

HOUR - returns the integer value of the hour of the day.

SECOND - returns the integer value representing the second of the time reading.

MILLISECOND - returns the integer value representing the millisecond segment of the time reading.

Some the date object methods include.

getDate() - Returns the day of the month in integer.

getDay() - Returns the day of the week in integer.

getFullYear() - Returns the year  in integer.

getHours() - Returns the hour  in integer.

getMilliseconds() - Returns the milliseconds  in integer.

getMinutes() - Returns the minutes  in integer.

getMonth() - Returns the month  in integer.

getSeconds() - Returns the seconds  in integer.

These are the most common methods that is used in date. If you are handling with records, make sure to format your date properly, as this is important in keeping data up to date.