Javascript 将“的12小时更改为24小时;getHours()”;方法

Javascript 将“的12小时更改为24小时;getHours()”;方法,javascript,Javascript,hello向某人展示了我如何添加24小时格式或想删除am和pm需要帮助,请 函数formatDateTime(日期){ var now=新日期(); var zpad_mins=':'+(date.getMinutes()12){ 返回(date.getHours()-12)+zpad_mins+'pm'; } 返回日期。getHours()+zpad_mins+'am'; }这将有所帮助 function DisplayCurrentTime(date) {

hello向某人展示了我如何添加24小时格式或想删除am和pm需要帮助,请

函数formatDateTime(日期){
var now=新日期();
var zpad_mins=':'+(date.getMinutes()<10?'0':'')+date.getMinutes();
如果(date.getYear()!=now.getYear()){
返回“”+(1900+date.getYear());
}如果((date.getMonth()!=now.getMonth())||
(date.getDate()!=now.getDate()){
返回日期。getDate()+“”+chrome.i18n.getMessage(
'month'+date.getMonth()+'abbr');
}else if(date.getHours()==12){
返回'12'+zpad_mins+'pm';
}else if(date.getHours()>12){
返回(date.getHours()-12)+zpad_mins+'pm';
}
返回日期。getHours()+zpad_mins+'am';
}
这将有所帮助

         function DisplayCurrentTime(date) {
          var hours = 
           date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
          var minutes = 
           date.getMinutes() < 10 ? "0" + date.getMinutes():date.getMinutes();
          var seconds = 
            date.getSeconds() < 10 ? "0"+date.getSeconds():date.getSeconds();                              
            var time = hours + ":" + minutes + ":" + seconds;
            return time  
           };

          console.log(DisplayCurrentTime(new Date()))
函数显示当前时间(日期){
var小时=
date.getHours()<10?“0”+date.getHours():date.getHours();
var分钟=
date.getMinutes()<10?“0”+date.getMinutes():date.getMinutes();
var秒=
date.getSeconds()<10?“0”+date.getSeconds():date.getSeconds();
变量时间=小时+“:”+分钟+“:”+秒;
返回时间
};
console.log(DisplayCurrentTime(new Date()))

默认情况下,它将使用24小时格式。因此,只需删除其中的部分-12并附加AM和PMnow.format(“UTC:h:MM:ss TT Z”);你可以使用下面的链接来理解谢谢你的回答不幸的是,我没有那么多关于.js的经验,我将尝试实现你的建议,但首先谢谢你