求助关于时间JS出现NaN错误
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/09/13 02:36:47
求助关于时间JS出现NaN错误
var today=new Date();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
var timeValue = " " + ((hours >12) "下午 "+hours -12 :"上午 "+hours); timeValue += ((minutes < 10) ":0" :":") + minutes+" ";
调用时分钟没问题,但是小时出现NaN,请问需要怎么修改?
var today=new Date();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
var timeValue = " " + ((hours >12) "下午 "+hours -12 :"上午 "+hours); timeValue += ((minutes < 10) ":0" :":") + minutes+" ";
调用时分钟没问题,但是小时出现NaN,请问需要怎么修改?
// hours - 12 用括号括起来
var timeValue = " " + ((hours >12) ? "下午 "+ (hours -12) : "上午 "+hours);
var timeValue = " " + ((hours >12) ? "下午 "+ (hours -12) : "上午 "+hours);