@{ DateTime nowTime = System.DateTime.Now; }
$(function () {
var currentDate = '@nowTime.ToString("yyyyMMdd HH:mm:ss")';
var currentYear = '@nowTime.Year';
var currentMonth = '@nowTime.Month';
var currentDay = '@nowTime.Day';
var currentHour = '@nowTime.Hour';
var currentMinute = '@nowTime.Minute';
var currentSecond = '@nowTime.Second';
setInterval(function () {
if (parseInt(currentSecond) < 59) {
currentSecond = parseInt(currentSecond) + 1;
} else {
currentSecond = "0";
currentMinute = parseInt(currentMinute) + 1; //分钟加一,秒钟置零
if (parseInt(currentMinute) == 60) {
currentMinute = "0";
currentHour = parseInt(currentHour) + 1; //小时加一,分钟置零
if (parseInt(currentHour) == 24) {
currentHour = "0";
currentDay = parseInt(currentDay) + 1; //日期加一,小时置零
var tempMonth = parseInt(currentMonth);
if (parseInt(tempMonth) == 1 || parseInt(tempMonth) == 3 || parseInt(tempMonth) == 5 || parseInt(tempMonth) == 7 || parseInt(tempMonth) == 8 || parseInt(tempMonth) == 10 || parseInt(tempMonth) == 12) { //大月
if (parseInt(currentDay) > 31) {
currentDay = "1";
currentMonth = parseInt(currentMonth) + 1; //月份加一,日期置零
if (parseInt(currentMonth) > 12) {
currentMonth = "1";
currentYear = parseInt(currentYear) + 1; //年份加一,月份置零
}
}
} else { //小月
if (parseInt(currentMonth) == 2) { //二月
if ((parseInt(currentYear) % 4 == 0 && parseInt(currentYear) % 100 != 0) || (parseInt(currentYear) % 400 == 0)) { //是润年
if (parseInt(currentDay) > 29) {
currentDay = "1";
currentMonth = parseInt(currentMonth) + 1;
}
} else { //非润年
if (parseInt(currentDay) > 28) {
currentDay = "1";
currentMonth = parseInt(currentMonth) + 1;
}
}
} else { //非二月
if (parseInt(currentDay) > 30) {
currentDay = "1";
currentMonth = parseInt(currentMonth) + 1;
}
}
}
}
}
}
var theFirstTime = currentYear + (parseInt(currentMonth) < 10 ? ("0" + currentMonth.toString()) : currentMonth.toString()) + (parseInt(currentDay) < 10 ? ("0" + currentDay.toString()) : currentDay.toString()); //年月日 20130530
var theSecondTime = (parseInt(currentHour) < 10 ? ("0" + currentHour.toString()) : currentHour.toString()) + ":" + (parseInt(currentMinute) < 10 ? ("0" + currentMinute.toString()) : currentMinute.toString()) + ":" + (parseInt(currentSecond) < 10 ? ("0" + currentSecond.toString()) : currentSecond.toString()); //时分秒 15:17:23
$("#currentTime").html(theFirstTime + " <font color='#FFF000' style='font-size:16px;'>" + theSecondTime + "</font>");
}, 1000);
});