SOURCE

//1. 日期的初始化
myDate = new Date();
myDate = new Date("December 19, 1983 03:24:00");
myDate = new Date(1983,11,19);
myDate = new Date(1983,11,17,3,24,0);

console.log(myDate);

//2. 获取时间的毫秒数
var dateMilSecs = Date.now(); 
console.log(dateMilSecs);

var date = new Date(); 
dateMilSecs = date.getTime(); //1657847935962
console.log(dateMilSecs);


//3. 时间间隔
var start = Date.now(); 
console.log(start); //毫秒数, 1657847354070
//做一些事情
var end = Date.now();
var elaspsed = end-start; // 毫秒数

function calculateFuncRunTime(func){
   var start = Date.now(),funcRtn = func(),end = Date.now();
   console.log("函数运行的时间:"+(end-start)+"毫秒");
   return funcRtn;
}


function hello(){
    var rtn = 1;
    for(var i in 1000000){
        rtn +=i;
        rtn /=2;
    }
    return rtn;
}

calculateFuncRunTime(hello);


//4. 转换为ISO 8601 时间格式
function ISODateString(d){
    function pad(n){ return n<10?'0'+n:n} //小于10的数字在前面补0
    return d.getUTCFullYear()+'-'
    + pad(d.getUTCMonth()+1)+'-'
    + pad(d.getUTCDate())+'T'
    + pad(d.getUTCHours())+':'
    + pad(d.getUTCMinutes())+':'
    + pad(d.getUTCSeconds())+'Z'}

var d = new Date(); //2022-07-15T01:54:17Z
console.log(ISODateString(d)); 


console.log(Ext.Date.format(new Date(),'Y/m/d'));
console 命令行工具 X clear

                    
>
console