JavaScript Date (날짜) 대상 설명
8698 단어 JavaScriptDate시간.
1. Date 대상 을 만 드 는 문법:
var myDate=new Date();
:Date 。
2. Date 대상 속성
(1)constructor Date 。
:
object.constructor
constructor 。
<script type="text/javascript"> var test=new Date(); if (test.constructor==Array) {document.write("This is an Array");} if (test.constructor==Boolean) {document.write("This is a Boolean");} if (test.constructor==Date) {document.write("This is a Date");} if (test.constructor==String) {document.write("This is a String");} </script>
(2)prototype
。
:
object.prototype.name=value
3. Date 대상 방법 (1) Date (): 당일 의 날짜 와 시간 을 되 돌려 줍 니 다.
<script type="text/javascript"> document.write(Date()); </script>
:Fri Apr 22 2016 17:24:21 GMT+0800 ( )
5 :
new Date("month dd,yyyy hh:mm:ss");
new Date("month dd,yyyy");
new Date(yyyy,mth,dd,hh,mm,ss);
new Date(yyyy,mth,dd);
new Date(ms);
(2) getDate (): 달의 어느 날 로 돌아 갑 니 다.
<script type="text/javascript"> var d = new Date(); document.write(d.getDate()); </script>
:22
(3) getDay (): 요일 을 나타 내 는 어느 날 의 숫자 를 되 돌려 줍 니 다.우 리 는 숫자 가 아 닌 요일 의 이름 을 출력 할 수 있 습 니 다.
<script type="text/javascript"> var d=new Date(); var weekday=new Array(7); weekday[0]="Sunday"; // , weekday[1]="Monday"; weekday[2]="Tuesday"; weekday[3]="Wednesday"; weekday[4]="Thursday"; weekday[5]="Friday"; weekday[6]="Saturday"; document.write("Today it is " + weekday[d.getDay()]) </script>
(4) getMonth (): 달 을 나타 내 는 숫자 를 되 돌려 줍 니 다.반환 값 은 0 (1 월) 에서 11 (12 월) 사이 의 정수 이다.우 리 는 달의 이름 을 출력 할 수 있 습 니 다:
<script type="text/javascript">
var d=new Date();
var month=new Array(12);
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";
document.write("The month is " + month[d.getMonth()])
</script>
(5) getFullYear (): 연 도 를 나타 내 는 4 자리 숫자 를 되 돌려 줍 니 다.
<script type="text/javascript"> var born = new Date("July 21, 1983 01:15:00"); document.write("I was born in " + born.getFullYear()); </script>
(6) getHours (): 시간의 시간 필드 를 되 돌려 줍 니 다.반환 값 은 0 (자정) 에서 23 (밤 11 시) 사이 의 정수 이다.(7) getMinutes (): 시간의 분 필드 를 되 돌려 줍 니 다.반환 값 은 0 ~ 59 사이 의 정수 이다.(8) getSeconds (): 시간의 초 를 되 돌려 줍 니 다.반환 값 은 0 ~ 59 사이 의 정수 이다.(9) getMilliseconds (): 시간의 밀리초 를 되 돌려 줍 니 다.(10) getTime (): 1970 년 1 월 1 일 사이 의 밀리초 수 를 되 돌려 줍 니 다.(! 밀리초) (11)
()
getTimezoneOffset() (GMT) 。
getUTCDate() Date (1 ~ 31)。
getUTCDay() Date (0 ~ 6)。
getUTCMonth() Date (0 ~ 11)。
getUTCFullYear() Date 。
getUTCHours() Date (0 ~ 23)。
getUTCMinutes() Date (0 ~ 59)。
getUTCSeconds() Date (0 ~ 59)。
getUTCMilliseconds() Date (0 ~ 999)。
setUTCDate() Date (1 ~ 31)。
setUTCMonth() Date (0 ~ 11)。
setUTCFullYear() Date ( )。
setUTCHours() Date (0 ~ 23)。
setUTCMinutes() Date (0 ~ 59)。
setUTCSeconds() Date (0 ~ 59)。
setUTCMilliseconds() Date (0 ~ 999)。
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
기초 정리 - 1문자 (String) 숫자 (Number) 불린 (Boolean) null undefined 심볼 (Symbol) 큰정수 (BigInt) 따옴표로 묶어 있어야 함 Not-A-Number - 숫자 데이터 / 숫자로 표...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.