[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/netkiller/netkiller.github.io/master/developer/html/date.html [Back]  [Original]

11.5.Date and TimeHome | | | | Github | | Facebook | Linkedin | Youtube | (Donations) | About
zhihu-card-default.svg [zhihu-card-default.svg]

11.5.Date and Time

var dateObject=new Date();
document.writeln(dateObject.toDateString());
Mon Mar 28 2016

document.writeln(dateObject.toLocaleDateString());
2016328

document.writeln(dateObject.toISOString())
2016-03-28T08:57:30.244Z

document.writeln(dateObject.toISOString().slice(0,10));
2016-03-28

document.writeln(dateObject.toISOString().slice(11,19));
09:11:12

document.writeln(dateObject.toTimeString().slice(0,9));
17:16:11

document.writeln(new Date("2016-3-30").getTime());
1459267200000
		
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
		

11.1.

			
function checkTime(i)    
{    
   if (i < 10) {    
       i = "0" + i;    
    }    
   return i;    
}
			
var ts = (new Date("2016-3-30")) - (new Date());//  
var dd = parseInt(ts / 1000 / 60 / 60 / 24, 10);//  
var hh = parseInt(ts / 1000 / 60 / 60 % 24, 10);//  
var mm = parseInt(ts / 1000 / 60 % 60, 10);//  
var ss = parseInt(ts / 1000 % 60, 10);//  
day = checkTime(dd);  
hour = checkTime(hh);  
minute = checkTime(mm);  
second = checkTime(ss);  

document.writeln(day + "" + hour + "" + minute + "" + second + "");  			
			
			


Web Proxy Viewer  |  New URL  |  Original Page