天天看點

js 日期date()轉換

Date常用方法:

擷取年月日時分秒

var myDate = new Date();

myDate.getYear(); //擷取目前年份(2位)

myDate.getFullYear(); //擷取完整的年份(4位,1970-????)

myDate.getMonth(); //擷取目前月份(0-11,0代表1月)

myDate.getMonth()+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(); //擷取目前日期

myDate.toLocaleTimeString(); //擷取目前時間

myDate.toLocaleString( ); //擷取日期與時間

var timestamp =Date.parse(new Date()); //不推薦; 毫秒改成了000顯示

var timestamp =(new Date()).valueOf(); //推薦;

var timestamp=new Date().getTime(); //推薦;

繼續閱讀