求助关于时间JS出现NaN错误
来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/08/19 08:40:09
求助关于时间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,请问需要怎么修改?
![求助关于时间JS出现NaN错误](/uploads/image/z/16918757-53-7.jpg?t=%E6%B1%82%E5%8A%A9%E5%85%B3%E4%BA%8E%E6%97%B6%E9%97%B4JS%E5%87%BA%E7%8E%B0NaN%E9%94%99%E8%AF%AF)
// hours - 12 用括号括起来
var timeValue = " " + ((hours >12) ? "下午 "+ (hours -12) : "上午 "+hours);
var timeValue = " " + ((hours >12) ? "下午 "+ (hours -12) : "上午 "+hours);