JavaScript toLocaleString() 方法
定义和用法
toLocaleString() 方法可根据本地时间把 Date 对象转换为字符串,并返回结果。
语法
dateObject.toLocaleString()
返回值
dateObject 的字符串表示,以本地时间区表示,并根据本地规则格式化。
实例
例子 1
在本例中,我们将根据本地时间把今天的日期转换为字符串:
<script type="text/javascript"> var d = new Date() document.write(d.toLocaleString()) </script>
输出:
2009年3月8日 8:11:30
例子 2
在本例中,我们将根据本地时间把具体的日期转换为字符串:
<script type="text/javascript">
var born = new Date("July 21, 1983 01:15:00")
document.write(born.toLocaleString())
</script>
输出:
1983年7月21日 1:15:00
本文介绍了JavaScript中的toLocaleString()方法,该方法能够将Date对象按照本地时间格式转换为字符串。文章通过两个实例展示了如何使用此方法来显示日期。
527

被折叠的 条评论
为什么被折叠?



