JavaScript toLocaleTimeString

JavaScript toLocaleTimeString 函数使用系统区域设置的转换,将给定日期和时间的“时间”部分转换为字符串。 toLocaleTimeString 函数的语法是

 Date.toLocaleTimeString()

在这里,我们使用它们来本地化时间字符串函数,以使用系统区域设置将今天日期和时间的时间部分转换为字符串。

<!DOCTYPE html>
<html>
<head>
    <title> JS  </title>
</head>
<body>
    <h1> Example </h1>
<script>
  var dt = Date();  
  document.write("Date and Time : " + dt + "<br/>");

  var x = dt.toLocaleTimeString();
  document.write("After = " + x);
</script>
</body>
</html>
Example

Date and Time: Mon Dec 31 2012 22:45:32 GMT+0530 (Indian Standard Time)
After = 22:45:32

JavaScript to Locale Time String 示例以字符串格式返回自定义日期和时间的“时间”部分。

<!DOCTYPE html>
<html>
<head>
    <title> JavaScriptto Locale Time String Function  </title>
</head>
<body>
    <h1> JavaScripttoLocaleTimeStringExample </h1>
<script>
  var dt = Date(2012, 11, 31, 22, 45, 32);
  document.write("Date and Time : " + dt + "<br/>");

  var x = dt.toLocaleTimeString();
  document.write("After toLocaleTimeString() = " + x);
</script>
</body>
</html>
toLocaleTimeString Function Example