js取得時間の各種関数
10087 ワード
Jsは現在の日付時間及びその他の操作var myDate=new Date();myDate.getYear()//現在の年(2桁)myDate.getFulYear()//完全な年(4桁、1970-???)を取得するmyDate.get Month()//現在の月(0-11,0は1月を表します)myDate.get Date()//現在の日(1-31)mysDate.getDay()//今周X(0-6,0は日曜日を表します)myDate.getTime()//現在の時間(1970.0.1からのミリ秒数)を取得するmyDate.get Hours()/.現在の時間数(0-23)myDate.get Minutes()//現在の分数(0-59)myDate.get Seconds()//現在の秒数(0-59)myDate.get Milliconds()//現在のミリ秒数(0-999)myDate.toLocareDateString()//現在の日付var mytime=myste.toLocaleTimeString()//現在の時間myDate.toLocareStering()//日付と時間の取得
日付時間スクリプトライブラリのメソッドリスト
Date.prototype.is Leape.Date.prototype.Format日付フォーマットDate.prototype.DateAdd日付計算Date.prototype.DateDiff比較日付差分Datet.prototype.tostring日付変換文字列Date.toArry日付は、配列Datet.protodattyParttypeの日付に分割されます.Date.prototype.WeekNumOfYear判定日付の所在年の第数週StringToDate文字列転送日付型IsValidDate検証日付有効性CheckDateTime完全日付時間検査daysBetween日付の日数差
jsコード:
//----------------------------------------------------------------------Date.prototype.isLeape=function(){return(0 this.getYear()%4&((((this.getsYear)%100!=0)
//---------------------------------------------------------日付フォーマットYY/yyy/YY/yyは年/MM/M月/W/月/W/月/w週/d d/DD/d日付/h h/hh/H時間/m m/m分/s s/SS/s/s/s/S/秒/-------------------------------------------------------------------------Fottttmart Fotforr[日]、‘一’、‘二’、‘三’、‘四’、‘五’、‘六’;
//±-----------------------------------------------------------------------------------------------------------------------------------------------DateOne,DateTwo){var OnetOne=DateOne.substring(5,Datenf)){('-')+1);var OneYear=DateOne.substring(0,DateOne.indexOf('-');
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------(60000*Number);case‘h’:return new Date(Datee.parse(dtTmp)+(360000*Number);case‘d’:returnnew Date(Date.parse)+(8640000*Number));case‘Darnetttttttttttttttttttttttmmmmmmmmmmber"(Darne(86………………………………………………………………………………………………………………………………………………………………………………………dtTmp.getFulYear(),(dtmp.getMonth()+Number*3,dtTmp.getDate()dtTmp.getHours()、dtTmp.getMinutes()、dtTmp.getSeconds();case‘m’:return new Date(dtttttmp.getFulYear()、(dttmpmp.getMonth()+Number.dtttttttttttttttdber,dtttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt:return new Date((dtmp.getFulYear)+Number)、dtTmp.getMonth()、dtTmp.getDate()、dtTmp.getHours()、dttmp.getMinutes()、dtTmp.get Seconds();
//±--------------------------------------------------------------------Date.prototype.DateDiff=Fnction(strect val,dt End){var dtStart=this;if(typeof dtStart=End=string)が文字列だったら{dtEnd=StringToDate(dtEnd);s wittch(stInterval){case‘s’:returnrn parseInt((dtEnt-dtStart)/1000);case‘n’:return parseInt((dtEnd-dtStart)/60000;catttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttdtStart)/8640000);case‘w’:return parseInt((dtEnd-dtStart)/(8640000*7);case‘m’:return(dtEnd.getMonth()+1)+((((())-dtEnd.getFulYear()-dtStart.getFlaYear()-12)-(dtStart.getMonth()+1);case‘y’:Enturt Enter(Enter)
//±----------------------------------------------------------------------Date.prototype.toString=function(showWeek){var myDate=this;var str=mysted.toLocareDateString(Weifer)(Weif)[‘日’、‘一’、‘二’、‘三’、‘四’、‘五’、‘六’、str+=’曜日+Week[myDate.getDay()];return str;
////±---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------フレストストストストワード(Darvar SDate=Datestststststr===DateStr.DateStr===DateStr.restr.restr.replplplacr.replacr.((((((//Datestr))))){DateStr/DateStr/DateStr/Date(/)MM-(/)DDまたはYYYYY-(/)M-(/)DDまたはYYYYY-(/)M-(/)DまたはYYYY YYYY Y-(/)(/)-Dは''/////データベースに置き換えられます.適法な日付は、YYYYYY-M/DD(2003-3/21)で、データベースは自動的にYYYY-M-M-M-DDM-DDM-DDD-DDD-DDD-D-DDD-DDD-DDD-DDD-DDD-DDD-DDD-DDD-1フォーマット/1/1/////(((((//))))//////////////////////////,');if(s=')//説明フォーマットはYYY-M-DDまたはYYYY-M-DDまたはYYYY-M-DまたはYYYYYY-M-DまたはYYYYYY-M-Dを満足しています.{var t=new Date(sDate.replace(/-/g、'));var ar=sDate.split(/[-/]/);if(ar[0]!=t.getYear()[1]!=t.getMonth()+1??|?|||à||||àààààààààà)))(((===============を選択します.閏年に注意してください.');return false;}else{/alert(「エラーの日付フォーマット!フォーマットは、YYYY-M-DDまたはYYYY/MM/DD.閏年に注意してください.」)、return false;return true;
////±------------------------------------------------------------------------------------------------------------------------------------------------{var reg=/"""(\d+)-(\d{{{1,2))-(\\d{1、、((((\\d))))))))))))((\\d{1、(\\d{1、(((\\d{1、、、、、、(((\\d)))))))))))))////////((((\\d(r==null)return false;r[2]=r[2]-1;var d=new Date(r[1],r[2],r[3],r[4],r[5],r[6]);if(d.getFulYear()==r[1])return false;if(d.getMonth()====r[2]return falstfalse(Dalstrtre))=Dalstreefl(DalstFurtFrerereme=Dalstfter))====================(Dalstrtrtrtrtrtrtrtrtrtrtrtrtreeftertereeeft[FFurtFurttFure(Dalse;if(d.get Minutes()==r[5]return false;if(d.get Seconds()=r[6]return false;return true;
----------------------------------------------------------------------------------------------------------------Date. prototype.toAray=function(){var myDate=this;var mAray=Aray();mAray[0]=mAray=mAray[0==mdateteteteteDaDaDaDaDaDaDateteFFray[mDaDaDaDaDatFrary[0]==mdateFray[mdateFray=mdateFray=mdateFray=mdateFray=mDaDaDaDaDaDaDatHours();myAray[4]=myDate.get Minutes();myAray[5]=myDate.get Seconds();return myAray;
//±----------------------------------------------日データ情報/|パラメータintervalはデータの種類/|y年m月d日w周h時n分s秒/±------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------‘日’、‘一’、‘二’、‘三’、‘四’、‘五’、‘六’;switch(interval){case‘y’:partStr=mdate. getFulllYear();break;case‘m’:partStSter=mdate.getMonth(+1);break=break=dedededededededededededededededededededededededededetttttttttttttttcagee(parte:parte:parte:parte=parte:parte=mbree=mbree=mbree=mbree:parteeek;case‘w w’:partStr=myDate.WeekNumOfYear();break;case‘h’:partStr=myDate.get Hours();break;case‘n’:partStr=myDate.get Minutes();break;case‘s’:partStr=myDate.get Seconds();break;
//±--------------------------------------------------------------------------------------------------------Date.prototype.MaxDayOfDate=function(){var mysDate=this;var ary=mdate.toAray();var datetetetet 1、()=vateteted 1)=1、()=new date[Daard 1)=1]、[Daday]、[Daard 1]、((()=Daday[Daday]]])=Daard 1、[Daard 1]、[/day[Da;var result=dateDiff(date 1.Format),[yyy-M-dd],date 2.Format(yyy-M-dd]);return reult;
//±----------------------------------------------------------------------------------------------------------------Date.prototype.WeekNumOfYear=function(){var myDate=this;var ary=mys Date=mys.toary=mys.toary=toary=toary=toAray();vary=mys=mys=toar=toar=toray=toArr=toArr=toray=toArr=toray=toray=('>);document.write(‘myDate=Datue('+monte+'-''+day+'-'-'''、''+year+'));document.write(‘relt=DatePart’);docurn.
////±----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
表示するには、現在の日付に時間がかかります.
function CurrentTime(){var now=new Date();
日付時間スクリプトライブラリのメソッドリスト
Date.prototype.is Leape.Date.prototype.Format日付フォーマットDate.prototype.DateAdd日付計算Date.prototype.DateDiff比較日付差分Datet.prototype.tostring日付変換文字列Date.toArry日付は、配列Datet.protodattyParttypeの日付に分割されます.Date.prototype.WeekNumOfYear判定日付の所在年の第数週StringToDate文字列転送日付型IsValidDate検証日付有効性CheckDateTime完全日付時間検査daysBetween日付の日数差
jsコード:
//----------------------------------------------------------------------Date.prototype.isLeape=function(){return(0 this.getYear()%4&((((this.getsYear)%100!=0)
//---------------------------------------------------------日付フォーマットYY/yyy/YY/yyは年/MM/M月/W/月/W/月/w週/d d/DD/d日付/h h/hh/H時間/m m/m分/s s/SS/s/s/s/S/秒/-------------------------------------------------------------------------Fottttmart Fotforr[日]、‘一’、‘二’、‘三’、‘四’、‘五’、‘六’;
str=str.replace(/yyyy|YYYY/,this.getFullYear());
str=str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 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(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours());
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(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds());
str=str.replace(/s|S/g,this.getSeconds());
return str;
)//±-----------------------------------------------------------------------------------------------------------------------------------------------DateOne,DateTwo){var OnetOne=DateOne.substring(5,Datenf)){('-')+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);
)----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------(60000*Number);case‘h’:return new Date(Datee.parse(dtTmp)+(360000*Number);case‘d’:returnnew Date(Date.parse)+(8640000*Number));case‘Darnetttttttttttttttttttttttmmmmmmmmmmber"(Darne(86………………………………………………………………………………………………………………………………………………………………………………………dtTmp.getFulYear(),(dtmp.getMonth()+Number*3,dtTmp.getDate()dtTmp.getHours()、dtTmp.getMinutes()、dtTmp.getSeconds();case‘m’:return new Date(dtttttmp.getFulYear()、(dttmpmp.getMonth()+Number.dtttttttttttttttdber,dtttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt:return new Date((dtmp.getFulYear)+Number)、dtTmp.getMonth()、dtTmp.getDate()、dtTmp.getHours()、dttmp.getMinutes()、dtTmp.get Seconds();
//±--------------------------------------------------------------------Date.prototype.DateDiff=Fnction(strect val,dt End){var dtStart=this;if(typeof dtStart=End=string)が文字列だったら{dtEnd=StringToDate(dtEnd);s wittch(stInterval){case‘s’:returnrn parseInt((dtEnt-dtStart)/1000);case‘n’:return parseInt((dtEnd-dtStart)/60000;catttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttdtStart)/8640000);case‘w’:return parseInt((dtEnd-dtStart)/(8640000*7);case‘m’:return(dtEnd.getMonth()+1)+((((())-dtEnd.getFulYear()-dtStart.getFlaYear()-12)-(dtStart.getMonth()+1);case‘y’:Enturt Enter(Enter)
//±----------------------------------------------------------------------Date.prototype.toString=function(showWeek){var myDate=this;var str=mysted.toLocareDateString(Weifer)(Weif)[‘日’、‘一’、‘二’、‘三’、‘四’、‘五’、‘六’、str+=’曜日+Week[myDate.getDay()];return str;
////±---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------フレストストストストワード(Darvar SDate=Datestststststr===DateStr.DateStr===DateStr.restr.restr.replplplacr.replacr.((((((//Datestr))))){DateStr/DateStr/DateStr/Date(/)MM-(/)DDまたはYYYYY-(/)M-(/)DDまたはYYYYY-(/)M-(/)DまたはYYYY YYYY Y-(/)(/)-Dは''/////データベースに置き換えられます.適法な日付は、YYYYYY-M/DD(2003-3/21)で、データベースは自動的にYYYY-M-M-M-DDM-DDM-DDD-DDD-DDD-D-DDD-DDD-DDD-DDD-DDD-DDD-DDD-DDD-1フォーマット/1/1/////(((((//))))//////////////////////////,');if(s=')//説明フォーマットはYYY-M-DDまたはYYYY-M-DDまたはYYYY-M-DまたはYYYYYY-M-DまたはYYYYYY-M-Dを満足しています.{var t=new Date(sDate.replace(/-/g、'));var ar=sDate.split(/[-/]/);if(ar[0]!=t.getYear()[1]!=t.getMonth()+1??|?|||à||||àààààààààà)))(((===============を選択します.閏年に注意してください.');return false;}else{/alert(「エラーの日付フォーマット!フォーマットは、YYYY-M-DDまたはYYYY/MM/DD.閏年に注意してください.」)、return false;return true;
////±------------------------------------------------------------------------------------------------------------------------------------------------{var reg=/"""(\d+)-(\d{{{1,2))-(\\d{1、、((((\\d))))))))))))((\\d{1、(\\d{1、(((\\d{1、、、、、、(((\\d)))))))))))))////////((((\\d(r==null)return false;r[2]=r[2]-1;var d=new Date(r[1],r[2],r[3],r[4],r[5],r[6]);if(d.getFulYear()==r[1])return false;if(d.getMonth()====r[2]return falstfalse(Dalstrtre))=Dalstreefl(DalstFurtFrerereme=Dalstfter))====================(Dalstrtrtrtrtrtrtrtrtrtrtrtrtreeftertereeeft[FFurtFurttFure(Dalse;if(d.get Minutes()==r[5]return false;if(d.get Seconds()=r[6]return false;return true;
----------------------------------------------------------------------------------------------------------------Date. prototype.toAray=function(){var myDate=this;var mAray=Aray();mAray[0]=mAray=mAray[0==mdateteteteteDaDaDaDaDaDaDateteFFray[mDaDaDaDaDatFrary[0]==mdateFray[mdateFray=mdateFray=mdateFray=mdateFray=mDaDaDaDaDaDaDatHours();myAray[4]=myDate.get Minutes();myAray[5]=myDate.get Seconds();return myAray;
//±----------------------------------------------日データ情報/|パラメータintervalはデータの種類/|y年m月d日w周h時n分s秒/±------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------‘日’、‘一’、‘二’、‘三’、‘四’、‘五’、‘六’;switch(interval){case‘y’:partStr=mdate. getFulllYear();break;case‘m’:partStSter=mdate.getMonth(+1);break=break=dedededededededededededededededededededededededededetttttttttttttttcagee(parte:parte:parte:parte=parte:parte=mbree=mbree=mbree=mbree:parteeek;case‘w w’:partStr=myDate.WeekNumOfYear();break;case‘h’:partStr=myDate.get Hours();break;case‘n’:partStr=myDate.get Minutes();break;case‘s’:partStr=myDate.get Seconds();break;
//±--------------------------------------------------------------------------------------------------------Date.prototype.MaxDayOfDate=function(){var mysDate=this;var ary=mdate.toAray();var datetetetet 1、()=vateteted 1)=1、()=new date[Daard 1)=1]、[Daday]、[Daard 1]、((()=Daday[Daday]]])=Daard 1、[Daard 1]、[/day[Da;var result=dateDiff(date 1.Format),[yyy-M-dd],date 2.Format(yyy-M-dd]);return reult;
//±----------------------------------------------------------------------------------------------------------------Date.prototype.WeekNumOfYear=function(){var myDate=this;var ary=mys Date=mys.toary=mys.toary=toary=toary=toAray();vary=mys=mys=toar=toar=toray=toArr=toArr=toray=toArr=toray=toray=('
////±----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var converted = Date.parse(DateStr);
var myDate = new Date(converted);
if (isNaN(myDate))
{
//var delimCahar = DateStr.indexOf('/')!=-1?'/':'-';
var arys= DateStr.split('-');
myDate = new Date(arys[0],--arys[1],arys[2]);
}
return myDate;
)表示するには、現在の日付に時間がかかります.
function CurrentTime(){var now=new Date();
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var hh = now.getHours(); //时
var mm = now.getMinutes(); //分
var clock = year + "-";
if(month < 10)
clock += "0";
clock += month + "-";
if(day < 10)
clock += "0";
clock += day + " ";
if(hh < 10)
clock += "0";
clock += hh + ":";
if (mm < 10) clock += '0';
clock += mm;
return(clock);
}