[英]Turn a String to a 24 hour time format, using moment.Js
I am trying to format a String into a 24 hour format using moment JS at the moment I am not getting the expected output, the below explains it in more detail: 我正在尝试使用片刻JS将字符串格式化为24小时格式,此时我没有得到预期的输出,下面将更详细地解释它:
How I am coverting 我是如何变态的
var testFormat = moment("9:00","HH:mm:ss");
I was hoping this would output: 我希望这会输出:
09:00:00 (24 Hour format) 09:00:00(24小时格式)
But for some reason is does not convert just the date, this is outputing the following: 但由于某种原因,只是不转换日期,这是输出以下内容:
1471507200000
You are using it wrong. 你错了。 You can provide a format as the second argument to moment. 您可以提供格式作为时刻的第二个参数。 So in your case it would be: 所以在你的情况下它将是:
var myMoment = moment("9:00","H:mm");
To get the moment
. 为了得到moment
。 Now you can format it the way you want: 现在你可以按照你想要的方式格式化它:
myMoment.format("HH:mm:ss");
moment("13:15:00", "h:mm:ss").format("hh:mm A"); 时刻(“13:15:00”,“h:mm:ss”)。格式(“hh:mm A”); it will give 12 hrs format 它将提供12小时格式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.