读书人

十 ways to format time and date usi

发布时间: 2012-09-04 14:19:30 作者: rapoo

10 ways to format time and date using JavaScript

?

JavaScript has an inbuilt support for dates and times with its?Date?object. The methods of the?Date?object return various values associated with date and time.

To start working with dates and time, we first initialize a variable and assign it a value with the?new?operator and the?Date()?constructor. The main function of the new operator withDate()?constructor is to create a new date object that is stored in the variable. Here is the code:

var d = new Date();

Thus, variable?d?contains a new date object. We can now call the various methods of this date object.

?

Format #1: date-month-year

The three methods that we would be using are:

读书人网 >JavaScript

热点推荐