/
timeStyle :日期时间格式
/
function getDateTime(timeStyle) {
var date = new Date();
var year = dategetFullYear(); //年
var month = dategetMonth() + 1; //月
var day = dategetDate(); //日
var hour = dategetHours(); //小时
var minute = dategetMinutes(); //分钟
var second = dategetSeconds(); //秒钟
//月份小于10时显示为'0X'
if (month < 10) {
month = "0" + month;
}
//天数小于10时显示为'0X'
if (day < 10) {
day = "0" + day;
}
//小时小于10时显示为'0X'
if (hour < 10) {
hour = "0" + hour;
}
//分钟小于10时显示为'0X'
if (minute < 10) {
minute = "0" + minute;
}
//秒钟小于10时显示为'0X'
if (second < 10) {
second = "0" + second;
}
var colon = ":";
var dash = "-";
var result = "";
if (timeStyle == "yyyy-MM-dd HH:mm") {
result = year + dash + month + dash + day + " "
+ hour + colon + minute;
}
else if (timeStyle == "yyyy-MM-dd HH:mm:ss") {
result = year + dash + month + dash + day + " "
+ hour + colon + minute + colon + second;
}
else {
result = year + dash + month + dash + day;
}
result += " ";
if(hour<=5){
result += "凌晨好!";
}else if(hour<=8){
result += "早上好!";
}else if(hour<=12){
result += "上午好!";
}else if(hour<=13){
result += "中午好!";
}else if(hour<=18){
result += "下午好!";
}else if(hour<=22){
result += "晚上好!";
}else if(hour<=24){
result += "深夜了,晚安!";
}
return result;
}
function runTime(){
showTimeinnerHTML=getDateTime('yyyy-MM-dd HH:mm:ss');
setTimeout("runTime()",1000);
}
<font id="showTime">这里显示时间!</font>
以上就是关于JavaScript显示本地时间代码全部的内容,包括:JavaScript显示本地时间代码、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)