Ric*_*rna 104 javascript momentjs
如何以24小时格式而不是12小时显示时间?
我正在使用moment.js.
我很确定这些线可能与它有关.
meridiem : function (hours, minutes, isLower) {
if (hours > 11) {
return isLower ? 'pm' : 'PM';
} else {
return isLower ? 'am' : 'AM';
}
},
Run Code Online (Sandbox Code Playgroud)
怎么改呢?
Jør*_*n R 322
你读过文档吗?
它指出
H, HH 24 hour time
h, or hh 12 hour time (use in conjunction with a or A)
Run Code Online (Sandbox Code Playgroud)
因此,说明你的时间HH将给你24小时格式,hh并将给出12小时格式.
小智 10
moment("01:15:00 PM", "h:mm:ss A").format("HH:mm:ss")
**o/p: 13:15:00 **
Run Code Online (Sandbox Code Playgroud)
它将24小时格式转换为12小时格式.
您可以使用
moment("15", "hh").format('LT')
Run Code Online (Sandbox Code Playgroud)
像这样将时间转换为12小时格式 3:00 PM
//Format 24H use HH:mm
let currentDate = moment().format('YYYY-MM-DD HH:mm')
console.log(currentDate)
//example of current time with defined Time zone +1
let currentDateTm = moment().utcOffset('+0100').format('YYYY-MM-DD HH:mm')
console.log(currentDateTm)Run Code Online (Sandbox Code Playgroud)
<script src="https://momentjs.com/downloads/moment.js"></script>Run Code Online (Sandbox Code Playgroud)
使用它来获取从 00:00:00 到 23:59:59 的时间
如果您的时间使用“LT 或 LTS”来确定日期
var now = moment('23:59:59','HHmmss').format("HH:mm:ss")
Run Code Online (Sandbox Code Playgroud)
** https://jsfiddle.net/a7qLhsgz/ **