Code
/**
*
* 生成随机颜色
* @return rand
*/
function randomColor( ) {
var rand = Math.floor(Math.random( ) * 0xFFFFFF).toString(16);
if(rand.length == 6){
return rand;
}else{
return randomColor();
}
}
/**
* 反转颜色
* @return 0xFFFFFF-color
*/
function turnColor(color) {
var color=(0xFFFFFF-Math.floor("0x"+color)).toString(16);
var len = 6-color.length;
for(var i=0; len!=i; i++) {
color = "0"+color;
}
return color;
}
/**
* 倒计时
* @param time Date
* @return *日*时*分*秒
*/
function nowToDate(time){
var now = new Date();
if(time>now){
var tmp = time - now;
//秒
tmp = Math.floor(tmp/1000);
second = tmp%60;
//分
tmp = Math.floor(tmp/60);
minute = tmp%60;
//时
tmp = Math.floor(tmp/60);
hour = tmp%24;
//天
date = Math.floor(tmp/24);
return "距离"+time.toLocaleString()+ "还有"+
date+"天"+
hour+"时"+
minute+"分"+
second+"秒";
}else{
return "你指定的时间已过去";
}
/**
*
* 生成随机颜色
* @return rand
*/
function randomColor( ) {
var rand = Math.floor(Math.random( ) * 0xFFFFFF).toString(16);
if(rand.length == 6){
return rand;
}else{
return randomColor();
}
}
/**
* 反转颜色
* @return 0xFFFFFF-color
*/
function turnColor(color) {
var color=(0xFFFFFF-Math.floor("0x"+color)).toString(16);
var len = 6-color.length;
for(var i=0; len!=i; i++) {
color = "0"+color;
}
return color;
}
/**
* 倒计时
* @param time Date
* @return *日*时*分*秒
*/
function nowToDate(time){
var now = new Date();
if(time>now){
var tmp = time - now;
//秒
tmp = Math.floor(tmp/1000);
second = tmp%60;
//分
tmp = Math.floor(tmp/60);
minute = tmp%60;
//时
tmp = Math.floor(tmp/60);
hour = tmp%24;
//天
date = Math.floor(tmp/24);
return "距离"+time.toLocaleString()+ "还有"+
date+"天"+
hour+"时"+
minute+"分"+
second+"秒";
}else{
return "你指定的时间已过去";
}