如何不使用 toLocaleString 显示秒数

How not to show seconds with toLocaleString

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString 表示:

second The representation of the second. Possible values are "numeric", "2-digit".

"numeric" 和“2 位数”有什么区别?几秒什么都不显示怎么办?我省略了 second 选项,它仍然显示。

This manual helped me understanding the date system hope it helps you too

Microsoft Office Excel stores dates as sequential numbers that are called serial values. For example, in Microsoft Office Excel for Windows, January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,448 days after January 1, 1900. Office Excel stores times as decimal fractions because time is considered a portion of a day. The decimal number is a value ranging from 0 (zero) to 0.99999999, representing the times from 0:00:00 (12:00:00 A.M.) to 23:59:59 (11:59:59 P.M.).

Because dates and times are values, they can be added, subtracted, and included in other calculations. You can view a date as a serial value and a time as a decimal fraction by changing the format of the cell that contains the date or time to General format.

另一个将是: Mysql based interpretation

Date values with two-digit years are ambiguous because the century is unknown. Such values must be interpreted into four-digit form because MySQL stores years internally using four digits.

For DATETIME, DATE, and TIMESTAMP types, MySQL interprets dates specified with ambiguous year values using these rules:

Year values in the range 00-69 are converted to 2000-2069.

Year values in the range 70-99 are converted to 1970-1999.

For YEAR, the rules are the same, with this exception: A numeric 00 inserted into YEAR(4) results in 0000 rather than 2000. To specify zero for YEAR(4) and have it be interpreted as 2000, specify it as a string '0' or '00'.

我在这里使用了其他文档作为参考,因为那里有基础 同样希望他们也能帮到你。

2 位数字用 0 填充,而数字不是。不指定秒数(未定义)是您省略它们的方式。但是,您确实需要指定您想要小时和秒。类似于:

var date = new Date();
var options = { hour: 'numeric', minute: '2-digit' };
console.log(date.toLocaleString('en-US', options));