var mydate = new date();
mydate.getyear(); //獲取當前年份(2位)
mydate.getfullyear(); //獲取完整的年份(4位,1970-????)
mydate.getmonth(); //獲取當前月份(0-11,0代表1月)注意別忘了+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( ); //獲取日期與時間
// 日期格式化
// 格式 yyyy/yyyy/yy/yy 表示年份
// mm/m 月份
// w/w 星期
// dd/dd/d/d 日期
// hh/hh/h/h 時間
// mm/m 分鐘
// ss/ss/s/s 秒 //
對date的擴充套件,將 date 轉化為指定格式的string
//月(m)、日(d)、小時(h)、分(m)、秒(s)、季度(q) 可以用 1-2 個佔位符,
//年(y)可以用 1-4 個佔位符,毫秒(s)只能用 1 個佔位符(是 1-3 位的數字)
//例子:
//(new date()).format("yyyy-mm-dd hh:mm:ss.s") ==> 2006-07-02 08:09:04.423
//(new date()).format("yyyy-m-d h:m:s.s") ==> 2006-7-2 8:9:4.18
date.prototype.format = function (fmt) ;
if (/(y+)/.test(fmt)) fmt = fmt.replace(regexp.$1, (this.getfullyear() + "").substr(4 - regexp.$1.length));
for (var k in o)
if (new regexp("(" + k + ")").test(fmt)) fmt = fmt.replace(regexp.$1, (regexp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}呼叫:
var time1 = new date().format("yyyy-mm-dd");
Js獲取當前日期時間
var mydate new date mydate.getyear 獲取當前年份 2位 mydate.getfullyear 獲取完整的年份 4位,1970 mydate.getmonth 獲取當前月份 0 11,0代表1月 mydate.getdate 獲取當前日 1 31 mydate.get...
JS獲取當前日期時間
var mydate new date var years mydate.getfullyear 從date 物件以四位數字返回年份 var months mydate.getmonth 從date 物件返回月份 0 11 var days mydate.getdate 從date物件返回乙個月中的...
Js獲取當前日期時間
var mydate new date mydate.getyear 獲取當前年份 2位 mydate.getfullyear 獲取完整的年份 4位,1970 mydate.getmonth 獲取當前月份 0 11,0代表1月 mydate.getdate 獲取當前日 1 31 mydate.get...