이 기사는 JS의 현재 날짜 및 서식 작업을 공유합니다. 특정 내용은 다음과 같습니다
var mydate = new date (); mydate.getyear (); // 현재 연도를 얻습니다 (2 자리) mydate.getLyEar (); // 1 년 내내 얻습니다 (4 자리, 1970- ????) mydate.getMonth (); // 현재 달을 가져옵니다 (0-11, 0은 1 월을 나타냅니다) mydate.getDate (); // 현재 하루를 가져옵니다 (1-31) mydate.getDay (); // 현재 주 X를 가져옵니다 (0-6, 0은 일요일을 나타냅니다) mydate.getTime (); // 현재 시간을 가져옵니다 (1970.1.1부터 시작하는 밀리 초) mydate.gethours (); // 현재 시간 수를 가져옵니다 (0-23) mydate.getMinutes (); // 현재 분 수를 가져옵니다 (0-59) mydate.getSeconds (); // 현재 초 수를 가져옵니다 (0-59) mydate.getMilliseconds (); // 현재 밀리 초 (0-999) mydate.tolocaledatestring (); // 현재 날짜를 가져옵니다 var myTime = myDate.ToloCaletImestring (); // 현재 시간을 가져옵니다. mydate.tolocalestring (); // 현재 시간을 가져옵니다. mydate.tolocalestring (); // 날짜와 시간을 얻습니다
날짜 및 시간 및 시간 스크립트 라이브러리 방법 목록
date.prototype.isleapyear 판사는 연도를 도약합니다
date.prototype.format 날짜 형식
date.prototype.dateadd 날짜 계산
date.prototype.datediff 비교 날짜 차이
날짜 .prototype.tostring 날짜 to String
날짜 .prototype.toarray 날짜는 배열로 분할됩니다
date.prototype.datePart 날짜에 대한 정보를 얻습니다
date.prototype.maxdayofdate 날짜가있는 달의 최대 일수가 소요됩니다.
date.prototype.weeknumofyear 날짜가 다음 일주일을 결정합니다.
StringTodate String까지
IsValidDate 날짜 유효성을 확인하십시오
CheckDateTime 전체 날짜 및 시간 확인
날짜 차이 사이의 날
JS 코드 :
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- DD/DD/D/D 날짜 // HH/HH/H/H 시간 // MM/M 분 // SS/SS/S/S Seconds//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- % 100) .tostring () : '0' + (this.getyear () % 100)); str = str.replace (/mm/, this.getmonth ()> 9? this.getmonth (). toString () : '0' + this.getMonth ()); str = str.replace (/m/g, this.getmonth ()); str = str.replace (/w | w/g, Week [this.getDay ()]; str = str.replace (/dd|dd/, this.getDate ()> 9? this.getDate (). toString () : '0' + this.getDate ()); str = str.replace (/d|d/g, this.getDate ()); str = str.replace (/hhohhh/ str = str.replace (/h|h/g, this.gethours ()); str = str.replace (/mm/, this.getminutes ()> 9? this.getminutes (). toString () : '0' + this.getMinutes ()); str = str.replace (/m/g, this.getminutes ()); str = str.replace (/m/g, this.getminutes ()); str = str.replace (/ss|ss/, this.getSeconds ()> 9? this.getSeconds (). toString () : '0' + this.getSeconds ()); str = str.replace (/s|s/g, this.getSeconds ()); Return str; } //+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- dateone.substring (5, dateone.lastindexof ( '-')); var oneday = dateone.substring (dateone.length, dateone.lastindexof ( '-')+1); var oneyear = dateone.substring (0, dateone.indexof ( '-')); var twomonth = datetwo.substring (5, datetwo.lastindexof ( '-')); var twoday = datetwo.substring (datetwo.length, datetwo.lastindexof ( '-')+1); var twoyear = datetwo.substring (0, datetwo.indexof ( '-')); var cha = ((date.parse (onemonth+'/'+oneday+'/'+oneyear)- date.parse (twomonth+'/'+twoday+'/'+twoyear))/86400000); Return Math.abs (Cha); } //+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ var dtTmp = this; switch (strinterval) {case 's': 새 날짜를 반환합니다 (date.parse (dttmp) + (1000 * 숫자)); 사례 'n': 새 날짜를 반환합니다 (date.parse (dttmp) + (60000 * 번호)); 사례 'H': 새 날짜를 반환합니다 (date.parse (dttmp) + (3600000 * 번호)); 사례 'D': 새 날짜를 반환합니다 (date.parse (dttmp) + (86400000 * 번호)); 사례 'W': 새 날짜를 반환합니다 (date.parse (dttmp) + (86400000 * 번호)); 사례 'W': 새 날짜를 반환합니다 (date.parse (dttmp) + (86400000 * 번호)); 사례 'W': 새 날짜를 반환합니다 (date.parse (dttmp) + (86400000 * 번호)); 사례 'W': 새 날짜를 반환합니다 (date.parse (dttmp) + (86400000 * 번호)); 사례 'W': 새 날짜를 반환합니다 (date.parse (dttmp) + (86400000 * 번호)); 사례 'W': 새 날짜를 반환합니다 (date.parse (dttmp) + (86400000 * 번호)); 사례 'W': 새 날짜를 반환합니다 (date.parse (dttmp) + ((86400000 * 7) * 번호); CASE 'Q': 새 날짜를 반환합니다 (DTTMP.GETLYEAR (), (dttmp.getMonth ()) + 번호*3, dttmp.getDate (), dttmp.gethours (), dttmp.getMinutes (), dttmp.getSeconds ()); CASE 'M': 새 날짜를 반환합니다 (DTTMP.GETLYEAR (), (DTTMP.GETMONTH ()) + 번호, DTTMP.GETDATE (), DTTMP.GETHOURS (), DTTMP.GETMINUTES (), DTTMP.GETSECONDS ()); CASE 'y': 새 날짜를 반환합니다 ((dttmp.getFallyEar () + 번호), dttmp.getMonth (), dttmp.getDate (), dttmp.gethours (), dttmp.getMinutes (), dttmp.getSeconds ()); } } //+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- The format is date type or valid date format string //+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 60000); CASE 'H': ParseInt를 반환합니다 ((DTEND -DTSTART) / 3600000); CASE 'D': ParseInt를 반환합니다 ((DTEND -DTSTART) / 86400000); CASE 'W': ParseInt를 반환합니다 ((DTEND -DTSTART) / (86400000 * 7)); case 'm': return (dtend.getmonth ()+1)+(((dtend.getlyear () -dtstart.getlyear ())*12) - (dtstart.getmonth ()+1); CASE 'y': return dtend.getLyEar () -dtStart.getFelyEar (); }} //+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------. + = '주' + 주 [mydate.getday ()]; } return str; } //+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // 형식이 yyyy- (/) mm-(/) dd 또는 yyyy- (/) m- (/) dd 또는 yyyy- (/) m-(/) d 또는 yyyy- (/) mm-(/) d를 만족시키는 경우, 데이터베이스에서 '//로 대체 될 수 있습니다. yyyy-mm-dd 형식으로 자동 변환 var s = sdate.replace (/[/d] {4,4} [/-/] {1} [/d] {1,2} [/-/] {1} [/d] {1,2}/g, ''); if (s == '') // 명령 형식은 yyy-mm-dd 또는 yyyy-m-dd 또는 yyyy-md 또는 yyyy-mm-d {var t = new date (sdate.replace (//-/g, '/')를 만족시킵니다. var ar = sdate.split (/[-/:]/); if (ar [0]! = t.getyear () || ar [1]! = t.getmonth ()+1 || ar [2]! = t.getDate ()) {// alert ( '잘못된 날짜 형식! 형식은 yyyy-mm-dd 또는 yyyy/mm/dd. lem에주의를 기울입니다.'); 거짓을 반환합니다. }} else {// alert ( '잘못된 날짜 형식! 형식은 다음과 같습니다. yyyy-mm-dd 또는 yyyy/mm/dd. 거짓을 반환합니다. } true를 반환합니다. } //+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- }) $/; var r = str.match (reg); if (r == null) false를 반환합니다. r [2] = r [2] -1; var d = 새 날짜 (r [1], r [2], r [3], r [4], r [5], r [6]); if (d.getlyear ()! = r [1]) false를 반환합니다. if (d.getmonth ()! = r [2]) false를 반환합니다. if (d.getDate ()! = r [3]) false를 반환합니다. if (d.gethours ()! = r [4]) false를 반환합니다. if (d.getMinutes ()! = r [5]) false를 반환합니다. if (d.getSeconds ()! = r [6]) false를 반환합니다. 진실을 반환하십시오. } //+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- myArray [3] = mydate.gethours (); myArray [4] = mydate.getMinutes (); myArray [5] = mydate.getSeconds (); MyArray를 반환하십시오. } //+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Week = [ 'Day', 'One', 'Two', 'Three', 'Four', 'Five', 'Six']; switch (interval) {case 'y': partstr = mydate.getlyear (); break; 사례 'm': partstr = mydate.getmonth ()+1; break; case 'd': partstr = mydate.getDate (); break; 사례 'w': partstr = week [mydate.getday ()]; break; 사례 'ww': partstr = mydate.weeknumofyear (); break; 사례 'h': partstr = week [mydate.getday ()]; break; 사례 'ww': partstr = mydate.weeknumofyear (); break; 사례 'h': partstr = mydate.gethours (); break; case 'n': partstr = mydate.getMinutes (); break; case 's': partstr = mydate.getSeconds (); break; } 반환 partstr; } //+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- (새 날짜 (Ary [0], ary [1] +1,1)); var date2 = date1.dateadd (1, 'm', 1); var result = datediff (date1.format ( 'yyyy-mm-dd'), date2.format ( 'yyyy-mm-dd')); 반환 결과; } //+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ a y = mydate.toArray (); var year = ary [0]; var month = ary [1] +1; var day = ary [2]; document.write ( '<script language = vbscript/n'); document.write ( 'mydate = datue (' '+month+'-'+day+'-'+year+' ')); document.write ( 'result = datePart ('ww ', mydate) /n'); document.write ( ' /n'); 반환 결과; } //+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Convert string to date type //| MM/DD/YYYY MM-DD-YYYY YYYY/MM/DD YYYY-MM-DD 형식 //+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 날짜 (arys [0],-arys [1], arys [2]); } return mydate; }그러한 시계를 구현하려면 :
2012 년 12 월 3 일 17:21:16 월요일
// 로컬 클록 함수 clockon () {var now = new Date (); var year = now.getlyear (); // getlylyear getyear var month = now.getmonth (); var date = now.getDate (); var day = now.getday (); var hour = now.gethours (); var minute = now.getminutes (); var sec = now.getSeconds (); var 주; Month = Month + 1; if (Month <10) Month = "0" + Month; if (날짜 <10) 날짜 = "0" + 날짜; if (Hour <10) Hour = "0" + 시간; if (minu <10) minute = "0" + minu; if (sec <10) sec = "0" + sec; var arr_week = 새로운 배열 ( "일요일", "월요일", "화요일", "목요일", "금요일", "토요일"); 주 = arr_week [day]; var time = ""; 시간 = 년 + "year" + month + "month" + date + "day" + " + Hour +": " + minu +": " + sec +" " + Week; $ ( "#bgclock"). html (시간); var timer = settimeout ( "clockon ()", 200);}위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.