如何在不显示秒的情况下使用.toLocaleTimeString()? [英] How do I use .toLocaleTimeString() without displaying seconds?
问题描述
我目前正在尝试显示用户的时间而不显示秒数。有没有办法可以使用Javascript的.toLocaleTimeString()?
I'm currently attempting to display the user's time without displaying the seconds. Is there a way I can do this using Javascript's .toLocaleTimeString()?
做这样的事情:
var date = new Date();
var string = date.toLocaleTimeString();
将显示用户每个单位的时间,例如目前它显示在下午3:39:15。我能够显示相同的字符串,只是没有秒吗? (例如下午3:39)
will display the user's time with every unit, e.g. currently it displays 3:39:15 PM. Am I able to display that same string, just without the seconds? (e.g. 3:39 PM)
推荐答案
您可以随时设置选项,基于此页面你可以设置,摆脱秒,像这样的东西
You can always set the options, based on this page you can set, to get rid of the seconds, something like this
var dateWithouthSecond = new Date();
dateWithouthSecond.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
受Firefox,Chrome,IE9 +和Opera支持。在您的网络浏览器控制台上试用它。
Supported by Firefox, Chrome, IE9+ and Opera. Try it on your web browser console.
这篇关于如何在不显示秒的情况下使用.toLocaleTimeString()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!