var d1:Date=new Date();
var d2:Date=new Date();
d2.setFullYear(2055,12,30);
d2.setHours(20,20,20);
trace(Math.floor((endD.getTime()-starD.getTime())/(1000*60));
以上是获取的时间的“分”,如果需要获取天、年、秒之类的东东,只需要加红色的字那里!
时间计算 以电脑现在的时间为基础 计时过去 与未来的时差
//月从 0 算起
var time:String = "2010-08-17 15:0:0";//1282026062291
trace(starTime(time,"format"));//00:52:16
function starTime(_time:*,_returnType:String = "format"):String
{
var StarTim:Number;
var nowTim:Date = new Date();
if (_time is String)
{
var tempArr1:Array = _time.split(" ");
var tempArr2:Array = (tempArr1[0] as String).split("-");
var tempArr3:Array = (tempArr1[1] as String).split(":");
var Year:Number = Number(tempArr2[0]);
var Moon:Number = Number(tempArr2[1]) - 1;
var Day:Number = Number(tempArr2[2]);
var Hous:Number = Number(tempArr3[0]);
var Min:Number = Number(tempArr3[1]);
var second:Number = Number(tempArr3[2]);
StarTim = Number(new Date(Year,Moon,Day,Hous,Min,second));
}
else if (_time is Number)
{
StarTim = _time;
}
var StartTime:Number = StarTim / 1000;
var EndTime:Number = Math.floor((Number(nowTim)/1000));
var JobTime:Number = EndTime - StartTime;
var JobDay:Number = Math.floor(JobTime / 86400);
var JobHous:Number=Math.floor((JobTime/3600$));
var JobMin:Number=Math.floor((JobTime/60`));
var JobSec:Number=Math.floor((JobTime`));
//trace(JobDay,JobHous,JobMin,JobSec);
if (_returnType == "format")
{
return ConvertTime(JobTime);
}
else if (_returnType == "second")
{
//负数为倒数 正数为正数
return JobTime.toString();
}
return "";
}
//格式化
function ConvertTime(_timeNum:int):String
{
return ( pad(Math.abs(int(_timeNum / 3600)).toString(),2) + ":" + pad(Math.abs(int(_timeNum % 3600 / 60)).toString(),2) + ":" + pad(Math.abs(int(_timeNum % 3600 % 60)).toString(),2) + "");
}
//补0
function pad(num:String, n:int):String
{
if ((num + "").length >= n)
{
return num;
}
return pad("0" + num, n);
}
var d2:Date=new Date();
d2.setFullYear(2055,12,30);
d2.setHours(20,20,20);
trace(Math.floor((endD.getTime()-starD.getTime())/(1000*60));
以上是获取的时间的“分”,如果需要获取天、年、秒之类的东东,只需要加红色的字那里!
时间计算 以电脑现在的时间为基础 计时过去 与未来的时差
//月从 0 算起
var time:String = "2010-08-17 15:0:0";//1282026062291
trace(starTime(time,"format"));//00:52:16
function starTime(_time:*,_returnType:String = "format"):String
{
var StarTim:Number;
var nowTim:Date = new Date();
if (_time is String)
{
var tempArr1:Array = _time.split(" ");
var tempArr2:Array = (tempArr1[0] as String).split("-");
var tempArr3:Array = (tempArr1[1] as String).split(":");
var Year:Number = Number(tempArr2[0]);
var Moon:Number = Number(tempArr2[1]) - 1;
var Day:Number = Number(tempArr2[2]);
var Hous:Number = Number(tempArr3[0]);
var Min:Number = Number(tempArr3[1]);
var second:Number = Number(tempArr3[2]);
StarTim = Number(new Date(Year,Moon,Day,Hous,Min,second));
}
else if (_time is Number)
{
StarTim = _time;
}
var StartTime:Number = StarTim / 1000;
var EndTime:Number = Math.floor((Number(nowTim)/1000));
var JobTime:Number = EndTime - StartTime;
var JobDay:Number = Math.floor(JobTime / 86400);
var JobHous:Number=Math.floor((JobTime/3600$));
var JobMin:Number=Math.floor((JobTime/60`));
var JobSec:Number=Math.floor((JobTime`));
//trace(JobDay,JobHous,JobMin,JobSec);
if (_returnType == "format")
{
return ConvertTime(JobTime);
}
else if (_returnType == "second")
{
//负数为倒数 正数为正数
return JobTime.toString();
}
return "";
}
//格式化
function ConvertTime(_timeNum:int):String
{
return ( pad(Math.abs(int(_timeNum / 3600)).toString(),2) + ":" + pad(Math.abs(int(_timeNum % 3600 / 60)).toString(),2) + ":" + pad(Math.abs(int(_timeNum % 3600 % 60)).toString(),2) + "");
}
//补0
function pad(num:String, n:int):String
{
if ((num + "").length >= n)
{
return num;
}
return pad("0" + num, n);
}