> JavaScript toLocaleString() 方法

JavaScript toLocaleString() 方法

定义和用法

toLocaleString() 方法可根据本地时间把 Date 对象转换为字符串,并返回结果。

语法

dateObject.toLocaleString()

返回值

dateObject 的字符串表示,以本地时间区表示,并根据本地规则格式化。

实例

例子 1

在本例中,我们将根据本地时间把今天的日期转换为字符串:

<script type="text/javascript">

var d = new Date()
document.write(d.toLocaleString())

</script>

输出:

例子 2

在本例中,我们将根据本地时间把具体的日期转换为字符串:

<script type="text/javascript">

var born = new Date("July 21, 1983 01:15:00")
document.write(born.toLocaleString())

</script>

输出:

TIY

toLocaleString()
如何使用 toLocaleString() 来根据本地时间把今天的日期转换为字符串。
参考手册

W3c0.com 提供的内容仅用于培训。我们不保证内容的正确性。通过使用本站内容随之而来的风险与本站无关。W3c0 简体中文版的所有内容仅供测试,对任何法律问题及风险不承担任何责任。 当使用本站时,代表您已接受了本站的使用条款和隐私条款。版权所有,保留一切权利。 鲁ICP备15022115号