JavaScript格式化日期输出

JavaScript Code


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
<script>

window.onload = function(){

Date.prototype.Format = function (fmt) {

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(fmt))

fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));

for (var k in o)

if (new RegExp("(" + k + ")").test(fmt))

fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));

return fmt;

}

var currenttime1 = new Date().Format("yyyy-MM-ddTHH:mm:ss");

var pselstart = document.getElementById("starttime");

pselstart.value = currenttime1;

var currenttime2 = new Date().Format("yyyy-MM-ddTHH:mm:ss");

var pselend = document.getElementById("endtime");

pselend.value = currenttime2;

}

</script>

时间: 2024-12-21 21:22:12

JavaScript格式化日期输出的相关文章

JavaScript格式化日期

查找格式化日期的方法大都是写日期扩展方法,也许是为了维持jquery easyUI 源码完整性, 1 // 对Date的扩展,将 Date 转化为指定格式的String 2 // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, 3 // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) 4 // 例子: 5 // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S")

JavaScript 格式化日期,转换时间日期格式

// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) // 例子: // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 // (new Date()).Format("

JAVASCRIPT 格式化日期

// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) // 例子: // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 // (new Date()).Format("

javascript自定义日期函数

1.格式化日期(YYYY-MM-DD) 代码: var DateFormat = function (date) { if (!(date instanceof Date)) { date = date.replace(/-/g, "/"); date = new Date(date); } var month = date.getMonth() + 1; var year = date.getFullYear(); var day = date.getDate(); if (mont

EL表达式格式化日期

在EL表达式中要显示“yyyy-MM-dd”格式的日期: 使用<fmt:>格式化标签 1 在页面上导入   <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 2 格式化日期<fmt:formatDate value="${XXX.date}" pattern="yyyy-MM-dd"/> Value :EL表达

iOS开发之格式化日期时间

iOS开发之格式化日期时间 在开发iOS程序时,有时候需要将时间格式调整成自己希望的格式,这个时候我们可以用NSDateFormatter类来处理.例如: //实例化一个NSDateFormatter对象 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; //设定时间格式,这里可以设置成自己需要的格式 [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

SQLServer格式化日期

SQL Server 格式化日期 CONVERT将某种数据类型的表达式显式转换为另一种数据类型.由于某些需求经常用到取日期格式的不同.现以下可在SQL Server中 将日期格式化.SQL Server 支持使用科威特算法的阿拉伯样式中的数据格式.在表中,左侧的两列表示将 datetime或 smalldatetime 转换为字符数据的style 值.给 style 值加 100,可获得包括世纪数位的四位年份 (yyyy). *    默认值(style 0 或 100.9 或 109.13 或

java初级应用----格式化---日期与时间格式化

问题描述: 实际编程过程中,常常要输出日期与时间,也需要对日期与时间进行格式化输出. 日期与时间都可以转化成String对象,所以可以使用String类中的format()函数对日期与时间字符串进行格式化. 编程思路: 1)明确String类中format()函数有两种重载形式: public static String format(String format, Object ... args) 功能:使得字符串按照参数所指定的格式被格式化,并且格式化之后的新字符串使用本地默认的语言环境 @p

python 格式化日期

常用的时间函数如下 获取当前日期:time.time() 获取元组形式的时间戳:time.local(time.time()) 格式化日期的函数(基于元组的形式进行格式化): (1)time.asctime(time.local(time.time())) (2)time.strftime(format[,t]) 将格式字符串转换为时间戳: time.strptime(str,fmt='%a %b %d %H:%M:%S %Y') 延迟执行:time.sleep([secs]),单位为秒 例1: