系統時間物件

2021-09-25 16:32:13 字數 1462 閱讀 5885

1.new date()

alert(new date());  //當前系統時間物件,當前指**讀到此處時

2.從中拆分出年月日等

//new date()的 typeof 是object

其他方法有;

//下面所有型別是number

var iyear = mytime.getfullyear();

var imonth = mytime.getmonth()+1; //?

var idate = mytime.getdate();

var iweek = mytime.getday();//0表示星期天

var ihours = mytime.gethours();

var imin = mytime.getminutes();

var isec = mytime.getseconds();

3.賦值形式

//數字形式

//字串形式

4.倒計時

var now=new date();

var future=new date(2013,5,23,9,34,2);

var t=math.floor((future-now)/1000);//首先,將毫秒轉化為秒

//直接拿來用

天:math.floor(t/86400)

時:math.floor(t%86400/3600)

分:math.floor(t%86400%3600/60)

秒:t%60

5.時間戳

new date().gettime() //返回從現在到2023年1月1日0點0分0秒的毫秒

第5天 js 系統時間物件

今天聽了一小節,js中如何獲取系統時間。最後做了乙個輪播圖效果,是在別人的 上修改的,一開始做了好半天,都沒做好,最後,在我的堅持下,終於做出來了。今天先到這兒,去休息了!獲取時間物件 new date getfullyear getmonth getdate getday gethours get...

js 時間物件 字元物件

var str hello 字面量方式建立 console.log str instanceof string falsevar str new string world console.log str instanceof string true console.log str instanceo...

js時間物件

1 當前時間換時間戳 var timestamp parseint new date gettime 1000 當前時間戳 document.write timestamp 2 當前時間換日期字串 var now new date var yy now.getfullyear 年var mm now...