JavaScript時間、フォーマット、変換及びDateオブジェクトまとめ
8519 ワード
, ,“Tue Jan 29 16:13:11 UTC+0800 2008” , , SimpleDateFormat , , Local , 。 , , ?
1、 (toLocaleDateString toLocaleTimeString)
:(new Date()).toLocaleDateString() + " " + (new Date()).toLocaleTimeString()
: 2008 1 29 16:13:11
2. (toDateString toTimeString)
: (new Date()).toDateString() + " " + (new Date()).toTimeString()
:Tue Jan 29 2008 16:13:11 UTC+0800
3. (toGMTString)
: (new Date()).toGMTString()
:Tue, 29 Jan 2008 08:13:11 UTC
4. (toUTCString)
: (new Date()).toUTCString()
:Tue, 29 Jan 2008 08:13:11 UTC
5.Date (toString)
: (new Date()).toString()
:Tue Jan 29 16:13:11 UTC+0800 2008
Date
Date 。
new Date()
new Date(milliseconds)
new Date(datestring)
new Date(year, month)
new Date(year, month, day)
new Date(year, month, day, hours)
new Date(year, month, day, hours, minutes)
new Date(year, month, day, hours, minutes, seconds)
new Date(year, month, day, hours, minutes, seconds, microseconds)
Date
milliseconds - JavaScript 1970 1 1
datestring - 。 Date.parse()
year - , 0-99, 1900
month - 0( )-11( )
day - 1-31
hours - 0( )-23
minutes - 0-59
seconds - 0-59
microseconds - 0-999
Date
,
, ,
, ,
,
var d1 = new Date();
document.write(d1.toString());
var d2 = new Date("2009-08-08 12:12:12);
document.write(d2.toString());
var d3 = new Date(2009, 8, 8);
document.write(d3.toString());
Date JavaScript , new 。
Date JavaScript , 1970 1 1 (GMT ) ( ), Date 。 getTime() Date Date , setTime() Date Date 。
Date
date. ( 1, 2,...);
Date. ();
date ,Date ,date.
Date.
var d=new Date();
var d2=Date.UTC();
JavaScript_Date
Date() -- Date
getDate() -- date (1-31)
getDay() -- date (0-6)
getFullYear() -- date
getHours() -- date (0-23)
getMilliseconds() -- date (0-999)
getMinutes() -- date (0-59)
getMonth() -- date (0-11)
getSeconds() -- date (0-59)
getTime() -- date ( )
getTimezoneOffset() -- UTC ,
getUTCDate() -- date (UTC) (1-31)
getUTCDay() -- date (UTC) (0-6)
getUTCFullYear() -- date (UTC)
getUTCHours() -- date (UTC) (0-23)
getUTCMilliseconds() -- date (UTC) (0-999)
getUTCMinutes() -- date (UTC) (0-59)
getUTCMonth() -- date (UTC) (0-11)
getUTCSeconds() -- date (UTC) (0-59)
getYear() -- date ( 1900)
Date.UTC() -- date (UTC)1970 1 1 ( )
setDate() -- date , date 1970 1 1 ( )
setFullYear() -- date , , date 1970 1 1 ( )
setHours() -- date , , , date 1970 1 1 ( )
setMilliseconds() -- date , date 1970 1 1 ( )
setMinutes() -- date , , , date 1970 1 1 ( )
setMonth() -- date , , date 1970 1 1 ( )
setSeconds() -- date , date 1970 1 1 ( )
setTime() -- date , date 1970 1 1 ( )
setUTCDate() -- date (UTC) , date 1970 1 1 ( )
setUTCFullYear() -- date (UTC) , , date 1970 1 1 ( )
setUTCHours() --- date (UTC) , , , date 1970 1 1 ( )
setUTCMilliseconds() -- date (UTC) , date 1970 1 1 ( )
setUTCMinutes() -- date (UTC) , , date 1970 1 1 ( )
setUTCMonth() -- date (UTC) , , date 1970 1 1 ( )
setUTCSeconds() -- date (UTC) , , date 1970 1 1 ( )
setYear() -- date ( 1900)
toDateString() -- date
toGMTString() -- date (GMT)
toLocaleDateString -- date
toLocaleTimeString -- date
toTimeString() -- date
toUTCString -- date (UTC)
Date.parse() -- , 1970 1 1 ( )
JavaScript_Date
Date() -- Date
getDate() -- date (1-31)
getDay() -- date (0-6)
getFullYear() -- date
getHours() -- date (0-23)
getMilliseconds() -- date (0-999)
getMinutes() -- date (0-59)
getMonth() -- date (0-11)
getSeconds() -- date (0-59)
getTime() -- date ( )
getTimezoneOffset() -- UTC ,
getUTCDate() -- date (UTC) (1-31)
getUTCDay() -- date (UTC) (0-6)
getUTCFullYear() -- date (UTC)
getUTCHours() -- date (UTC) (0-23)
getUTCMilliseconds() -- date (UTC) (0-999)
getUTCMinutes() -- date (UTC) (0-59)
getUTCMonth() -- date (UTC) (0-11)
getUTCSeconds() -- date (UTC) (0-59)
getYear() -- date ( 1900)
Date.parse() -- , 1970 1 1 ( )
setDate() -- date , date 1970 1 1 ( )
setFullYear() -- date , , date 1970 1 1 ( )
setHours() -- date , , , date 1970 1 1 ( )
setMilliseconds() -- date , date 1970 1 1 ( )
setMinutes() -- date , , , date 1970 1 1 ( )
setMonth() -- date , , date 1970 1 1 ( )
setSeconds() -- date , date 1970 1 1 ( )
setTime() -- date , date 1970 1 1 ( )
setUTCDate() -- date (UTC) , date 1970 1 1 ( )
setUTCFullYear() -- date (UTC) , , date 1970 1 1 ( )
setUTCHours() --- date (UTC) , , , date 1970 1 1 ( )
setUTCMilliseconds() -- date (UTC) , date 1970 1 1 ( )
setUTCMinutes() -- date (UTC) , , date 1970 1 1 ( )
setUTCMonth() -- date (UTC) , , date 1970 1 1 ( )
setUTCSeconds() -- date (UTC) , , date 1970 1 1 ( )
setYear() -- date ( 1900)
toDateString() -- date
toGMTString() -- date (GMT)
toLocaleDateString -- date
toLocaleTimeString -- date
toTimeString() -- date
toUTCString -- date (UTC)
Date.UTC() -- date (UTC)1970 1 1 ( )