ホームページ ウェブフロントエンド jsチュートリアル js(jQuery)の時刻と共通時刻のコレクションを取得するメソッドclasses_jquery

js(jQuery)の時刻と共通時刻のコレクションを取得するメソッドclasses_jquery

May 16, 2016 pm 05:18 PM

コードをコピー コードは次のとおりです。

$(function(){
var mydate = new Date( );
var t=mydate.toLocaleString();
/*alert(t);*/
$("#time").text(t); "#time ").load("Untitled-1.html");

});

afwef

組み込みの Date 関数を使用して JavaScript で時刻を取得します


var mydate = new Date();
mydate.getyear() // 現在の年 (2 桁) を取得します
mydate.getFull Year() ; //完全な年を取得します (4 桁、1970 年から????)
mydate.getMonth() // 現在の月を取得します (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();日付と時刻

日時スクリプト ライブラリ メソッド リスト

Date.prototype.isLeapyear うるう年の決定
Date.prototype.Format 日付の書式設定
Date.prototype.DateAdd 日付の計算
Date.prototype.DateDiff 日付の差を比較します
Date.prototype.toString 日付を文字列に変換します
Date.prototype.toArray 日付を配列に分割します
Date.prototype.DatePart 日付情報の一部を取得します
Date.prototype.MaxDayOfDate 日付が位置する月の最大日数を取得します
Date.prototype .WeekNumOfyear 日付が位置する年の週を決定します
StringToDate 文字列を日付型に変換します
IsValidDate 日付の有効性を確認します
CheckDateTime 日付と時刻のチェックを完了します
daysBetween 日付と日の差


コードをコピーコードは次のとおりです:

//------------------------------------------ ------ ----------
// うるう年の決定
//--------------------- ----------- -----------------------

Date.prototype.isLeap Year = function()
{
return (0==this .get Year()%4&&((this.get Year()0!=0)||(this.get Year()@0==0));
}

//--- -------------------------------------- -------
// 日付の形式
// 形式 YYYY/yyyy/YY/yy は年を表します
// MM/M 月
// W/w 週
// dd/DD/d/D 日付
// hh/HH/h/H 時間
// mm/m 分
// ss/SS/s/S 秒
// -------- -------------------------------------- ---
Date.prototype.Format = function(formatStr)
{
var str = formatStr;
var Week = ['日','一','二','三' ,'四','五','六'];

str=str.replace(/yyyy|YYYY/,this.getFullyear()); |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()); /M/g,this.getMonth()) ;

str=str.replace(/w|W/g,Week[this.getDay()]); .replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' this.getDate()); 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()); /s|S/g,this.getSeconds( ));

return str;

// --------------- ----------- ------------------------
//| 2 つの時刻間の日数の差を求めます。日付の形式は YYYY-MM-dd
/ /-------------------------------------- です。 ------------- --
function daysBetween(DateOne,DateTwo)
{
var OneMonth = DateOne.substring(5,DateOne.lastIndexOf ('-')) ;
var OneDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ('-') 1);
var OneDay = 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 '/' One Year)- Date.parse( TwoMonth '/' TwoDay '/' Two Year))/86400000 );
return Math.abs(cha)
}

// ------------ ----------- ------------------------
//| 日付計算
// ---------- --------------------------------------
Date.prototype.DateAdd = function (strInterval, Number) {
var dtTmp = this;
switch (strInterval) {
case 's' :return new Date(Date.parse(dtTmp)) (1000 * 数値));
case 'n' :return new Date(Date.parse(dtTmp) (60000 * Number));
case 'h' :return new Date(Date.parse(dtTmp) (3600000 * Number));
case 'd' :return new Date(Date.parse(dtTmp) (86400000 * Number)); ((86400000 * 7) * Number)) ;
case 'q' :return new Date(dtTmp.getFull Year(), (dtTmp.getMonth()) Number*3, dtTmp.getDate(), dtTmp.getHours( ), dtTmp.getMinutes(), dtTmp.getSeconds());
case 'm' :return new Date(dtTmp.getFull Year(), (dtTmp.getMonth()) Number, dtTmp.getDate(), dtTmp. getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
case 'y' :return new Date((dtTmp.getFull Year() Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours()、dtTmp.getMinutes()、dtTmp.getSeconds());
}
}

// --------------- ----------- ------------------------
//| 日付の違いを比較します。 dtEnd の形式は日付ですタイプまたは有効な日付形式文字列
/ /-------------------------------------- ---------- --
Date.prototype.DateDiff = function(strInterval, dtEnd) {
var dtStart = this;
if (typeof dtEnd == 'string' )/ /文字列の場合は日付型に変換します
{
dtEnd = StringToDate(dtEnd)
}
switch (strInterval) {
case 's' :return parseInt(( dtEnd - dtStart) / 1000);
case 'n' :return parseInt((dtEnd - dtStart) / 60000);
case 'h' :return parseInt((dtEnd - dtStart) / 3600000); >case 'd' :return parseInt((dtEnd - dtStart ) / 86400000);
case 'w' :return parseInt((dtEnd - dtStart) / (86400000 * 7)); return (dtEnd.getMonth() 1) ((dtEnd.getFull Year()-dtStart.getFull Year())*12) - (dtStart.getMonth() 1); - dtStart.getFullyear();
}
}

//------------------------------------------ --- --------
//| システムの toString メソッドをオーバーロードした日付出力文字列
// ------- ----------------------------------
Date.prototype.toString = function(showWeek)
{
var myDate= this;
var str = myDate.toLocaleDateString();
if (showWeek)
{
var Week = ['Day','Monday','Two' , 'three','four','five','six'];
str = 'week' Week[myDate.getDay()];
return
}

// -------------------------------------- ---- -------
//| 日付の正当性検証
//| 形式は YYYY-MM-DD または YYYY/MM/DD
// ---- ----------------------------------------------------
function IsValidDate(DateStr )
{
var sDate=DateStr.replace(/(^s |s $)/g,''); //両側のスペースを削除します。 =='') return true;
//形式が YYYY-(/)MM-(/)DD または YYYY-(/)M-(/)DD または YYYY-(/)M-(/ を満たす場合) )D または YYYY-(/)MM -(/)D は ''
に置き換えられます//データベースでは、法定日付は YYYY-MM/DD (2003-3/21) になります。データベースはYYYY-MM-DD 形式に自動的に変換します
var s = sDate.replace(/[d]{ 4,4 }[-/]{ 1 }[d]{ 1,2 }[-/]{ 1 } [d]{ 1,2 }/g,' ');
if (s=='') //記述形式は YYYY-MM-DD または YYYY-M-DD または YYYY-M-D または YYYY- を満たしますMM-D
{
var t= new Date(sDate.replace(/-/g,'/'));
var ar = sDate.split(/[-/:]/);
if(ar[0] != t.get Year() || ar[1] != t.getMonth() 1 || ar[2] != t.getDate())
{
//alert('日付形式が間違っています!形式は、YYYY-MM-DD または YYYY/MM/DD です。閏年に注意してください。 ');
return false;
}
}
else
{
//alert('日付の形式が間違っています! 形式は YYYY-MM-DD または YYYY/MM /DD。閏年に注意してください。');
戻り値
}
戻り値
}

// ------------------ -----------------------------
//| 日付と時刻のチェック
//| : YYYY-MM-DD HH:MM:SS
// ---------------------------------- ----------------
関数 CheckDateTime(str)
{
var reg = /^(d )-(d{ 1,2 })-( d{ 1,2 }) (d{ 1,2 }):(d{ 1,2 }):(d{ 1,2 })$/; 🎜>if(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.getFull Year()!=r[1])return false; [2]) false を返す;
if(d.getDate()!=r[3]) false を返す;
if(d.getHours()!=r[4]) false を返す; if(d.getMinutes()!=r[5])return false;
if(d.getSeconds()!=r[6])return true;
//------------------------------------------ --- ------
//| 日付を配列に分割します
// ------------------------ --- -----------------------
Date.prototype.toArray = function()
{
var myDate = this;
var myArray = Array();
myArray[0] = myDate.getFullyear();
myArray[1] = myDate.getMonth(); );
myArray[3] = myDate.getHours();
myArray[4] = myDate.getMinutes();
myArray[5] = myDate.getSeconds();
}

// -------------------------------------- ---- ----------
//| 日付データ情報を取得します
//| パラメータの間隔はデータ型を表します
//|週 ww 週 h 時 n 分 s 秒
//-------------------------------------- --------- ---------
Date.prototype.DatePart = function(interval)
{
var myDate = this; ';
var Week = [ '日','一','二','三','四','五','六'];
スイッチ(間隔)
{
ケース 'y' :partStr = myDate.getFull Year();break;
ケース 'm' :partStr = myDate.getMonth() 1;break;
ケース 'd' :partStr = myDate.getDate( );break;
case ' w' :partStr = Week[myDate.getDay()];break;
case 'ww' :partStr = myDate.WeekNumOf Year();break; :partStr = myDate.getHours(); Break;
case 'n' :partStr = myDate.getMinutes();break;
case 's' :partStr = myDate.getSeconds();break; }
partStr を返す
}

// ----------------------------- --------- ----------
//| 現在の日付の月の最大日数を取得します
// ------- ------------- -----------------------------
Date.prototype .MaxDayOfDate = function()
{
var myDate = this;
var ary = myDate.toArray();
var date1 = (new Date(ary[0],ary[1] 1) ,1));
var date2 = dateAdd(1,'m',1);
var result = date1.Format('yyyy-MM-dd'),date2.Format(' yyyy-MM-dd'));
結果を返します
}

// ----------------------- --------------- ---------------
//| 現在の日付が属する年の週を取得します。
// ---------- ----------------------------------- -----
Date.prototype.WeekNumOf Year = function ()
{
var myDate = this;
var ary = myDate.toArray();
var year = ary[0] ];
var month = ary[1] 1;
var day = ary[2];
document.write('< script language=VBScript> n'); ('myDate = DateValue('' 月 '-' 日 '- ' 年 '') n');
document.write('result = DatePart('ww', myDate) n'); .write(' n');
結果を返します
}

// ------------------------ --------------- ------------
//| 文字列を日付型に変換します
//| MM-dd-YYYY YYYY/MM/dd YYYY-MM- dd
// ---------------------------- ------ -------
function StringToDate(DateStr)
{

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]); >}
myDate を返す
}

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

JavaScriptの文字列文字を交換します JavaScriptの文字列文字を交換します Mar 11, 2025 am 12:07 AM

JavaScript文字列置換法とFAQの詳細な説明 この記事では、javaScriptの文字列文字を置き換える2つの方法について説明します:内部JavaScriptコードとWebページの内部HTML。 JavaScriptコード内の文字列を交換します 最も直接的な方法は、置換()メソッドを使用することです。 str = str.replace( "find"、 "置換"); この方法は、最初の一致のみを置き換えます。すべての一致を置き換えるには、正規表現を使用して、グローバルフラグGを追加します。 str = str.replace(/fi

jQuery日付が有効かどうかを確認します jQuery日付が有効かどうかを確認します Mar 01, 2025 am 08:51 AM

単純なJavaScript関数は、日付が有効かどうかを確認するために使用されます。 関数isvaliddate(s){ var bits = s.split( '/'); var d = new Date(bits [2] '/' bits [1] '/'ビット[0]); return !!(d &&(d.getmonth()1)== bits [1] && d.getdate()== number(bits [0])); } //テスト var

jQueryは要素のパディング/マージンを取得します jQueryは要素のパディング/マージンを取得します Mar 01, 2025 am 08:53 AM

この記事では、jQueryを使用して、DOM要素の内側のマージン値とマージン値、特に外側の縁と要素の内側の縁の特定の位置を取得して設定する方法について説明します。 CSSを使用して要素の内側と外側の縁を設定することは可能ですが、正確な値を取得するのは難しい場合があります。 // 設定 $( "div.header")。css( "margin"、 "10px"); $( "div.header")。css( "padding"、 "10px"); このコードはそうだと思うかもしれません

10 jQuery Accordionsタブ 10 jQuery Accordionsタブ Mar 01, 2025 am 01:34 AM

この記事では、10個の例外的なjQueryタブとアコーディオンについて説明します。 タブとアコーディオンの重要な違いは、コンテンツパネルの表示方法と非表示にあります。これらの10の例を掘り下げましょう。 関連記事:10 jQueryタブプラグイン

10 jqueryプラグインをチェックする価値があります 10 jqueryプラグインをチェックする価値があります Mar 01, 2025 am 01:29 AM

ウェブサイトのダイナミズムと視覚的な魅力を高めるために、10の例外的なjQueryプラグインを発見してください!このキュレーションされたコレクションは、画像アニメーションからインタラクティブなギャラリーまで、多様な機能を提供します。これらの強力なツールを探りましょう。 関連投稿: 1

ノードとHTTPコンソールを使用したHTTPデバッグ ノードとHTTPコンソールを使用したHTTPデバッグ Mar 01, 2025 am 01:37 AM

HTTP-Consoleは、HTTPコマンドを実行するためのコマンドラインインターフェイスを提供するノードモジュールです。 Webサーバー、Web Servに対して作成されているかどうかに関係なく、HTTPリクエストで何が起こっているかをデバッグして正確に確認するのに最適です

カスタムGoogle検索APIセットアップチュートリアル カスタムGoogle検索APIセットアップチュートリアル Mar 04, 2025 am 01:06 AM

このチュートリアルでは、カスタムGoogle検索APIをブログまたはWebサイトに統合する方法を示し、標準のWordPressテーマ検索関数よりも洗練された検索エクスペリエンスを提供します。 驚くほど簡単です!検索をyに制限することができます

jQueryはscrollbarをdivに追加します jQueryはscrollbarをdivに追加します Mar 01, 2025 am 01:30 AM

次のjQueryコードスニペットを使用して、Divコンテンツがコンテナ要素領域を超えたときにスクロールバーを追加できます。 (デモンストレーションはありません、それを直接firebugにコピーしてください) // d =ドキュメント // w =ウィンドウ // $ = jQuery var contentarea = $(this)、 wintop = contentarea.scrolltop()、 docheight = $(d).height()、 winheight = $(w).height()、 divheight = $( '#c

See all articles