JS獲取相關日期及調整格式

2022-01-30 02:32:27 字數 1327 閱讀 6091

var mydate = new date();

mydate.getyear();        //獲取當前年份(2位)

mydate.getfullyear();    //獲取完整的年份(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( );        //獲取日期與時間

日期時間指令碼庫方法列表

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 日期天數差

js**:

若要顯示:當前日期加時間(如:2009-06-12 12:00)

function curenttime()

**:

js中獲取日期格式

1 varmydate new date 2document.write mydate.getyear tostring 獲取當前年份 2位 3document.write mydate.getfullyear tostring 獲取完整的年份 4位,1970 4document.write myd...

js中獲取日期格式

1 varmydate new date 2document.write mydate.getyear tostring 獲取當前年份 2位 3document.write mydate.getfullyear tostring 獲取完整的年份 4位,1970 4document.write myd...

JS日期,JS獲取當前日期時間,js日期格式化

var mydate new date mydate.getyear 獲取當前年份 2位 mydate.getfullyear 獲取完整的年份 4位,1970 mydate.getmonth 獲取當前月份 0 11,0代表1月 注意別忘了 1 mydate.getdate 獲取當前日 1 31 my...