
要使用当前语言环境的约定以字符串形式返回日期的“时间”部分,请使用 toLocaleTimeString() 方法。
toLocaleTimeString 方法依赖于格式化日期的底层操作系统。它使用运行脚本的操作系统的格式约定将日期转换为字符串。例如,在美国,月份出现在日期之前 (04/15/98),而在德国,日期出现在月份之前 (15.04.98)。
示例
您可以尝试运行以下代码以将日期的“时间”部分作为字符串返回 -
<html>
<head>
<title>JavaScript toLocaleTimeString Method</title>
</head>
<body>
<script>
var dt = new Date(2018, 0, 15, 14, 16, 30);
document.write( "Formated Date - Time : " + dt.toLocaleTimeString() );
</script>
</body>
</html>

