js 日期轉換 strToDate

//定義日期字符串
var myStartStr = “2015-05-04 17:10:10” 
var myEndStr = “2015-05-04 17:10:10” 
var myStartDate = new Date(Date.parse(myStartStr.replace(/-/g, "/"))); 
var myEndDate = new Date(Date.parse(myEndStr.replace(/-/g, "/"))); 
//js判斷日期範圍
var currDate = new Date();
if(currDate<myStartDate||curr_date>myEndDate){
				alert("預約的時間不得超過有效期的範圍");
				return;
			}
//日期的操作: 
myStrDate.getYear();        //獲取當前年份(2位) 
myStrDate.getFullYear();    //獲取完整的年份(4位,1970-????) 
myStrDate.getMonth();       //獲取當前月份(0-11,0代表1月) 
myStrDate.getDate();        //獲取當前日(1-31) 
myStrDate.getDay();         //獲取當前星期X(0-6,0代表星期天) 
myStrDate.getTime();        //獲取當前時間(從1970.1.1開始的毫秒數) 
myStrDate.getHours();       //獲取當前小時數(0-23) 
myStrDate.getMinutes();     //獲取當前分鐘數(0-59) 
myStrDate.getSeconds();     //獲取當前秒數(0-59) 
myStrDate.getMilliseconds();    //獲取當前毫秒數(0-999) 
myStrDate.toLocaleDateString();     //獲取當前日期  2015/5/4
var mytime=myStrDate .toLocaleTimeString();     //獲取當前時間 下午5:10:47
myStrDate .toLocaleString( );        //獲取日期與時間  2015/5/4 下午5:10:47


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章