日期:2014-05-16  浏览次数:20357 次

JS发送信息时计算当前日期与所选日期之间的提示函数

function caculateDateTip(dt){

var MinMilli = 1000 * 60;

var HrMilli = MinMilli * 60;

var DyMilli = HrMilli * 24;

var nowFullDate = new Date();

var nowDate = new Date(nowFullDate.getFullYear(),nowFullDate.getMonth(),nowFullDate.getDate());

var nowWeek = nowDate.getDay();

var dtWeek = dt.getDay();

var t = Date.parse(dt) - Date.parse(nowDate);

var mday = Math.floor(Math.abs(t / DyMilli));

var tipStr = "";

if(mday <= 2){

switch(mday){

case 0: tipStr = "今天"; break;

case 1: tipStr = "明天"; break;

case 2: tipStr = "后天"; break;

}

}else{

var we = dtWeek - nowWeek;

var ndWeek = nowWeek + mday;

if(nowWeek == 0){

if(ndWeek <= 7){

switch(ndWeek){

case 3: tipStr = "下周三";break;

case 4: tipStr = "下周四";break;

case 5: tipStr = "下周五";break;

case 6: tipStr = "下周六";break;

case 7: tipStr = "下周日";break;

}

}else{

tipStr = dt.format("yyyy-MM-dd");

}

}else{

if(ndWeek <= 14){

switch(ndWeek){

case 3: tipStr = "本周三";break;

case 4: tipStr = "本周四";break;

case 5: tipStr = "本周五";break;

case 6: tipStr = "本周六";break;

case 7: tipStr = "本周日";break;

case 8: tipStr = "下周一";break;

case 9: tipStr = "下周二";break;

case 10: tipStr = "下周三";break;

case 11: tipStr = "下周四";break;

case 12: tipStr = "下周五";break;

case 13: tipStr = "下周六";break;

case 14: tipStr = "下周日";break;

}

}else{