js判斷表單日期和當前日期大小 精確到天

2022-09-21 05:21:08 字數 1275 閱讀 9220

// 獲取當前時間 

var currenttime = new date().tolocaledatestring('cn',); // 轉化成"yyyy/mm/dd"格式

currenttime = new date(currenttime);

// 獲取表單的填寫日期

var rq=$f("rq").val(); // 格式為"yyyy-mm-dd"

rq= rq.replace(/\-/g, "\/"); // 轉化成"yyyy/mm/dd"格式

rq= new date(rq);

if(currenttime <= rq)else

2.1 獲取時間並且格式化輸出
new date().tolocalestring(『cn』,) //2022/2/14 10:02:15

new date().tolocaledatestring(『cn』,) //2022/2/14

new date().tolocaletimestring(『cn』,) //10:02:15

2.2 分別獲取日期和時間
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( ); // 獲取日期與時間

Js判斷選擇日期不能小於當前日期

需求 選擇日期不能大於當前日期 new date 出來的時間帶有小時分秒等,這樣造成比較當天日期時產生問題 可以alert看看 thu jul 12 2018 00 00 00 gmt 0800 中國標準時間 thu jul 12 2018 08 39 33 gmt 0800 中國標準時間 new ...

js獲取當前日期

1.date 物件用於處理日期和時間。建立 date 物件的語法 var mydate new date date 物件會自動把當前日期和時間儲存為其初始值。2.引數形式有以下5種 new date month dd,yyyy hh mm ss new date month dd,yyyy new ...

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...