JS日期格式化(网上转载)
JS日期格式化(网上转载)
<!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日期格式化(网上转载)的更多相关文章
- 161226、js日期格式化
JavaScript Date format(js日期格式化) 方法一:// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季 ...
- 【JavaScript】 knockout.js 日期格式化借助【momentjs】
源:Knockout.js 日期格式化 源:momentjs
- JS获取当前日期时间及JS日期格式化
Js获取当前日期时间: var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整的年份( ...
- js 日期格式化函数(可自定义)
js 日期格式化函数 DateFormat var DateFormat = function (datetime, formatStr) { var dat = datetime; var str ...
- js日期格式化 扩展Date()
javascript Date format(js日期格式化) 方法一: // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(H/h).分(m).秒(s ...
- JS 日期格式化
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"& ...
- js日期格式化
<html> <head> <script> function test(){ //Js获取当前日期时间及其它操作 var myDate = new Date(); ...
- JS日期格式化函数性能优化篇
最近开发的软件中需要用到日志功能,其中有一个重要功能是显示日期和时间.于是网上搜了一把,搜到大量的日期格式化函数,不过比较了下,感觉代码都不够优雅,而且性能都不给力.对线上一些代码进行了评测,以下是一 ...
- javascript常用开发笔记:一个简单强大的js日期格式化方法
前言:一直没找到好用的javascript日期格式化工具,自己写了一个,方便以后复用 1.主要功能 (1)支持任意顺序的日期格式排列:yyyy=年,MM=月,dd=日,HH=时,mm=分,ss=秒,s ...
随机推荐
- css3 transition 实现图片放大缩小
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 归约函数reduce&映射数组map(笔记)
function forEach(array,action){ ;i<array.length;i++) action(array[i]); } function reduce(combine, ...
- 也说border-box盒模型
border-box是css3的一个新属性,使用这个属性,和以往的content-box比起来,会有诸多便利之处,bootstrap3也使用的是这个border-box,甚至很多人认为,border- ...
- 开始迈入Csharp的世界了
以前没有学过, 有点兴奋,完全是新手啊. 今天是元宵情人节, 加油↖(^ω^)↗ 分享一些话: 一则拉封丹寓言名字叫寓言<两个朋友>: 一天夜里,一个朋友突然去找另一个朋友.被吵 ...
- 三道题(关于虚表指针位置/合成64位ID/利用栈实现四则运算)
第一题 C++标准中,虚表指针在类的内存结构位置没有规定,不同编译器的实现可能是不一样的.请实现一段代码,判断当前编译器把虚表指针放在类的内存结构的最前面还是最后面. 第二题 在游戏中所有物品的实例 ...
- 第二篇、JavaScript常用的API
下面是我整理的一些JavaScript常用的API清单. 目录 元素查找 class操作 节点操作 属性操作 内容操作 css操作 位置大小 事件 DOM加载完毕 绑定上下文 去除空格 Ajax JS ...
- 我的博客已搬迁到http://www.lsworks.net
我的博客已搬迁到http://www.lsworks.net
- docker & nodejs & mongodb
Nodejs 应用简单的访问Mongodb 部署至Docker 1.本地简单的写能运行起来的一个nodejs (demo可写的更简单 一个post一个get即可) schemas user.js v ...
- java如何调用webservice接口
java调用WebService可以直接使用Apache提供的axis.jar自己编写代码,或者利用Eclipse自动生成WebService Client代码,利用其中的Proxy类进行调用.理论上 ...
- 洛谷 P1508 Likecloud-吃、吃、吃
P1508 Likecloud-吃.吃.吃 题目提供者JosephZheng 标签 动态规划 难度 普及/提高- 题目背景 问世间,青春期为何物? 答曰:"甲亢,甲亢,再甲亢:挨饿,挨饿,再 ...