JS日期格式化(网上转载)
2014-04-21 01:12
375 查看
JS日期格式化(网上转载)
来自:http://user.qzone.qq.com/526605799/2
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script type="text/javascript"> window.onload = function() { document.getElementById("textContext").value = new Date() .format("yyyy-MM-dd"); ; } /** * 时间对象的格式化 */ Date.prototype.format = function(format) { /* * format="yyyy-MM-dd hh:mm:ss"; */ var o = { "M+" : this.getMonth() + 1, "d+" : this.getDate(), "h+" : this.getHours(), "m+" : this.getMinutes(), "s+" : this.getSeconds(), "q+" : Math.floor((this.getMonth() + 3) / 3), "S" : this.getMilliseconds() } if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (this.getFullYear() + "") .substr(4 - RegExp.$1.length)); } for ( var k in o) { if (new RegExp("(" + k + ")").test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); } } return format; } /** * 时间对象的格式化 */ Date.prototype.format = function(format) { /* * format="yyyy-MM-dd hh:mm:ss"; */ var o = { "M+" : this.getMonth() + 1, "d+" : this.getDate(), "h+" : this.getHours(), "m+" : this.getMinutes(), "s+" : this.getSeconds(), "q+" : Math.floor((this.getMonth() + 3) / 3), "S" : this.getMilliseconds() } if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (this.getFullYear() + "") .substr(4 - RegExp.$1.length)); } for ( var k in o) { if (new RegExp("(" + k + ")").test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); } } return format; } </script> </head> <body> <input id="textContext"> <input type="button" onclick=""> </body> </html>
来自:http://user.qzone.qq.com/526605799/2
相关文章推荐
- 【转载】js获取当前日期,格式化成xxxx-xx-xx的格式(根据情况补零)
- js 日期与字符串互转 (网上没有的, 字符串转日期支持任意格式化字符串)
- 【转载】JS 中如何将字符串转化成日期&&日期格式化方法
- 【转载】JS 中如何将字符串转化成日期&&日期格式化方法
- 找的网上的js日期格式化问题出错了显示 一堆 NaN的东西
- javascript Date format(js日期格式化) 转载
- js/jq进行日期格式化为:yyyy-MM-dd 如2017-05-08
- JS日期格式化
- JS日期格式化,拿到时间段日期
- 【JavaScript】 knockout.js 日期格式化借助【momentjs】
- js 日期格式化及日期增减
- js时间戳格式化成日期格式
- JS追加日期时间格式化
- JavaScript前台页面使用jsjava对后台传过来的日期进行格式化
- 格式化日期(JS)
- javascript Date format(js日期格式化)
- js格式化日期
- 【转载】mysql 获取当前日期及格式化
- js 日期格式化工具类
- js日期转换和格式化