RSS구독하기:SUBSCRIBE TO RSS FEED
즐겨찾기추가:ADD FAVORITE
글쓰기:POST
관리자:ADMINISTRATOR
http://www.w3schools.com/js/js_obj_date.asp


JavaScript Date Object

previous next

The Date object is used to work with dates and times.


Examples

Return today's date and time
How to use the Date() method to get today's date.

getTime()
Use getTime() to calculate the years since 1970.

setFullYear()
How to use setFullYear() to set a specific date.

toUTCString()
How to use toUTCString() to convert today's date (according to UTC) to a string.

getDay()
Use getDay() and an array to write a weekday, and not just a number.

Display a clock
How to display a clock on your web page.


Complete Date Object Reference

For a complete reference of all the properties and methods that can be used with the Date object, go to our complete Date object reference.

The reference contains a brief description and examples of use for each property and method!


Defining Dates

The Date object is used to work with dates and times.

We define a Date object with the new keyword. The following code line defines a Date object called myDate:

var myDate=new Date()

Note: The Date object will automatically hold the current date and time as its initial value!


Manipulate Dates

We can easily manipulate the date by using the methods available for the Date object.

In the example below we set a Date object to a specific date (14th January 2010):

var myDate=new Date()
myDate.setFullYear(2010,0,14)

And in the following example we set a Date object to be 5 days into the future:

var myDate=new Date()
myDate.setDate(myDate.getDate()+5)

Note: If adding five days to a date shifts the month or year, the changes are handled automatically by the Date object itself!


Comparing Dates

The Date object is also used to compare two dates.

The following example compares today's date with the 14th January 2010:

var myDate=new Date()
myDate.setFullYear(2010,0,14)
var today = new Date()
if (myDate>today)
  alert("Today is before 14th January 2010")
else
  alert("Today is after 14th January 2010")

2007/10/29 20:24 2007/10/29 20:24
http://www.x2chi.com/trackback/122
nasty anal  | 2008/05/23 05:32
관심을 끌. 너가 좋을 동일할 지점을.
x2chi:Leading the Web to its Full Potential...
(웹의 모든 잠재력을 이끌어 내기 위하여...)
Leading the Web to its Full Potential... (웹의 모든 잠재력을 이끌어 내기 위하여...)
전체 (832)
내 이야기 (443)
관심거리들 (159)
웹&컴퓨팅 (173)
(주) 프로홈 (19)
건강 (7)
«   2012/02   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      
  1. buy carisoprodol online  20:32
    Rsd or produced it in photography. , https://w...
  2. 350mg carisoprodol  20:32
    Because they may act at the level of the cortex...
  3. soma info  20:32
    The intimates houston falls returned in the hu...
  4. soma pill identification  19:59
    and sore throat. Other severe side effects incl...
  5. ingrediants in soma  19:59
    Bernard rollin differs that quantities to direc...
  1. x2chi's me2day  2011
    슈퍼스타의 생각
  2. x2chi's me2day  2011
    슈퍼스타의 생각
  3. x2chi's me2day  2011
    슈퍼스타의 생각
  4. x2chi's me2day  2010
    슈퍼스타의 생각
  5. x2chi's me2day  2010
    슈퍼스타의 생각
  1. 2012/01 (1)
  2. 2011/10 (1)
  3. 2011/09 (9)
  4. 2011/08 (16)
  5. 2011/07 (10)