JavaScript Date (날짜) 대상 설명

8698 단어 JavaScriptDate시간.
날짜 대상 은 날짜 와 시간 을 처리 하 는 데 사 용 됩 니 다. 시간 과 관련 이 있 습 니 다. 예 를 들 어 타이머, 시계, 제출 시간 을 기록 합 니 다.주의해 야 할 것 은 반환 값 이 항상 두 자리 가 아니 라 이 값 이 10 보다 적 으 면 한 자리 숫자 만 되 돌아 오기 때문에 빈 자 리 를 0 으로 보충 해 야 한 다 는 것 이다.
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)。

좋은 웹페이지 즐겨찾기