`
freeskywcy
  • 浏览: 216475 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

Date toLocaleString()、toLocaleDateString()、toLocaleTimeString()方法

 
阅读更多
 
Date.toLocaleString()
 

功能:根据本地时间把Date对象转换为字符串。

语法:DateObject.toLocaleString()

参数:无。

返回值:Date对象的字符串表示,以本地时间区表示,并根据本地规则格式化。

Date.toLocaleDateString()

功能:根据本地时间把Date对象的日期部分转换为字符串。

语法:DateObject.toLocaleDateString()

参数:无。

返回值:Date对象日期部分的字符串表示,以本地时间区表示,并根据本地规则格式化。

Date.toLocaleTimeString()

功能:根据本地时间把Date对象的时间部分转换为字符串。

语法:DateObject.toLocaleTimeString()

参数:无。

返回值:Date对象时间部分的字符串表示,以本地时间区表示,并根据本地规则格式化。

注:时、分、秒字段各占2位数字,如果它们的值小于10,会自动添加前置0。

实例1

把Date对象转换为本地格式字符串。

<script type="text/javascript">
var d1 = new Date();
document.write( d1.toLocaleString() );
</script>

这段代码的输出效果:

2011年7月26日 16:30:39
实例2

把Date对象的日期部分转换为本地格式字符串。

<script type="text/javascript">
var d2 = new Date();
document.write( d2.toLocaleDateString() );
</script>

这段代码的输出效果:

2011年7月26日
实例3

把Date对象的时间部分转换为本地格式字符串。

<script type="text/javascript">
var d3 = new Date();
document.write( d3.toLocaleTimeString() );
</script>

这段代码的输出效果:

16:30:39

原文出自:http://hi.baidu.com/215846165/blog/item/b1b27becc7c004f5ce1b3eac.html

分享到:
评论

相关推荐

    JavaScript中的toString()和toLocaleString()方法的区别

    偶然之间用到这两个方法 然后在数字转换成字符串的时候,并没有感觉这两个方法有什么区别,如下: var e=123 e.toString() "123" e.toLocaleString() ...var sd=new Date() sd Wed Feb 15 2017 11:2

    DDate:Java数据处理日期Javascript

    可以DDate地在操作上方便地使用形式参数进行设置,以实现toLocaleDateString , toLocaleString和toLocaleTimeString 。帕拉configurar OSparâmetrosdestasfunçõesénecessárioinformar UMA串德localidade, ...

    【JavaScript源代码】JavaScript中时间格式化新思路toLocaleString().docx

     目录 1、时间格式化常规思路2、时间格式化toLocaleString() 1、时间格式化常规思路 2、时间格式化toLocaleString() 研究Object对象的时候,看到了 toLocaleString() 这个方法可以很简单的实现时间格式化。...

    javascript语言参考+教程 CHM

    toLocaleTimeString 方法; toLocaleUpperCase 方法; toLowerCase 方法; toPrecision 方法; toString 方法; toTimeString 方法; toUpperCase 方法; toUTCString 方法; ubound 方法; unescape 方法; unshift...

    JS实现日期时间动态显示的方法

    [removed]setInterval("jnkc[removed]=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000); [removed] &lt;/body&gt; &lt;/html&gt; 希望本文所述对大家Java

    javascript文档

    getVarDate 方法 返回 Date 对象中的 VT_DATE。 getYear 方法 返回 Date 对象中的年份。 Global 对象 是一个固有对象,目的是将全局方法集中在一个对象中。 global 属性 返回一个 Boolean 值,标记正则表达式使用...

    微软JavaScript手册

    getVarDate 方法 返回 Date 对象中的 VT_DATE。 getYear 方法 返回 Date 对象中的年份。 Global 对象 是一个固有对象,目的是将全局方法集中在一个对象中。 global 属性 返回一个 Boolean 值,标记正则表达式使用...

    JScript 语言参考

    getVarDate 方法 返回 Date 对象中的 VT_DATE。 getYear 方法 返回 Date 对象中的年份。 Global 对象 是一个固有对象,目的是将全局方法集中在一个对象中。 global 属性 返回一个 Boolean 值,标记正则表达式使用...

    utc2locale:从 Date#toUTCString() 到 Date#toLocaleString() 的流式方法

    utc2locale 从 Date#toUTCString() 到 Date#toLocaleString() 的流式方法。安装 $ npm install -g utc2locale用法正确运行 $ tail -f /path/to/your/log | utc2locale或者 $ utc2locale &lt;/path/to/your/log与 ...

    JavaScript权威指南

    The Date Object Section 3.10. Regular Expressions Section 3.11. Error Objects Section 3.12. Primitive Data Type Wrapper Objects Chapter 4. Variables Section 4.1. Variable Typing Section...

    JavaScript中toLocaleString()和toString()的区别实例分析

    主要介绍了JavaScript中toLocaleString()和toString()的区别,结合实例形式对比分析了toLocaleString()和toString()针对字符串、数组与日期操作过程中的区别与使用技巧,需要的朋友可以参考下

    JS Date对象进行格式化日期

    const date = new Date(2019, 0, 23, 17, 23, 42) 格式化结果: toString: Wed Jan 23 2019 17:23:42 GMT+0800 (中国标准时间) toDateString: Wed Jan 23 2019 toLocaleString: 2019/1/23 下午5:23:42 ...

    javascript显示动态时间的方法汇总

    1.第一种方法 当前时间: &lt;td id=CurrentTime&gt;&lt;/td&gt; [removed] function changetime(){ var ary = [星期日,星期一,星期二,星期三,星期四,星期五,星期六];...Timehtml[removed] = ''+date.toLocaleString()+'

    js时间戳格式化成日期格式的多种方法介绍

    return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' '); } alert&#40;getLocalTime(1293072805&#41;); 第二种 function getLocalTime(nS) { return new Date(parseInt(nS) * 1000)....

    javascript中打印当前的时间实现思路及代码

    date.toLocaleString(&#41;);//转化为本地时间 alert&#40;date.getFullYear(&#41;);//显示年份 alert&#40;date.getMonth(&#41; + 1);//显示月份 0-11,需要加1 alert&#40;date.getDate(&#41;);//显示一月中的日期 ...

    javascript页面动态显示时间变化示例代码

    date.toLocaleString(&#41;);//转化为本地时间 alert&#40;date.getFullYear(&#41;);//显示年份 alert&#40;date.getMonth(&#41; + 1);//显示月份 0-11,需要加1 alert&#40;date.getDate(&#41;);//显示一月中的日期 ...

    js获取系统当前时间

    网页特效|Linkweb.cn/Js|---...; charset=gb2312"&gt; &lt;/head&gt; &lt;script&gt;setInterval("linkweb.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000); &lt;/html&gt;

    javascript 数组的方法集合

    看看手册上的解释,拥有以下方法: 5iScRIPT.CNconcat方法 join方法 pop方法 push方法 reverse方法 shift方法 slice方法 sort方法 splice方法 toLocaleString方法 toString方法 unshift方法 valueOf方法 5iScRIPt.Cn...

Global site tag (gtag.js) - Google Analytics