如何使用当前语言环境的约定将日期转换为字符串?
htmljavascriptprogramming scripts
JavaScript date toLocaleString() 方法使用操作系统的本地约定将日期转换为字符串。
toLocaleString 方法依赖于底层操作系统来格式化日期。它使用运行脚本的操作系统的格式约定将日期转换为字符串。例如,在美国,月份出现在日期之前(04/15/98),而在德国,日期出现在月份之前(15.04.98)。
示例
您可以尝试运行以下代码来了解如何使用当前语言环境的约定将日期转换为字符串 −
<html> <head> <title>JavaScript toLocaleString Method</title> </head> <body> <script> var dt = new Date(2018, 0, 15, 14, 39, 7); document.write( "Formated Date : " + dt.toLocaleString() ); </script> </body> </html>