JS中增加日期格式化原型函数之prototype
/**
* javascript Date format(js日期格式化)
* 对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("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 * 调用:
var time1 = new Date().Format("yyyy-MM-dd");
var time2 = new Date().Format("yyyy-MM-dd HH:mm:ss");
*/
Date.prototype.format = function(format) {
var date = {
"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+)/i.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
}
for (var k in date) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1
? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
}
}
return format;
}
JS中增加日期格式化原型函数之prototype的更多相关文章
- JS中的日期内置函数
用JS中的日期内置函数实现在页面显示:“今天是:2013年9月26日14:32:45”. var date=new Date(Date.parse('9/26/2013 14:32:45')); ...
- JS中关于构造函数、原型链、prototype、constructor、instanceof、__proto__属性
在Javascript不存在类(Class)的概念,javascript中不是基于类的,而是通过构造函数(constructor)和原型链(prototype chains)实现的.但是在ES6中引入 ...
- js强大的日期格式化函数,不仅可以格式化日期,还可以查询星期,一年中第几天等
js强大的日期格式化,timestamp支持10位或13位的时间戳,或是时间字符串,同时支持android ios的处理,不只是日期的格式化还有其它方法,比如获 获取某月有多少天 .获取某个日期在这一 ...
- Date类型-演示JS中的日期
<script type="text/javascript"> /* *演示JS中的日期 */ var date = new Date(); document.writ ...
- JSON中的日期格式化
Json字符串中的日期格式化函数 ConvertJsonDate: function (jd) { var d = new Date(parseInt(jd.replace("/Date(& ...
- thymeleaf中的日期格式化
本篇介绍些thymeleaf中的日期格式化的方法: 1.用#dates.format来解决: <span th:text="${#dates.format(user.date, 'yy ...
- python中时间日期格式化符号
python中时间日期格式化符号: import time print(time.strftime('%Y%H%M%S', time.localtime())) 运行结果: 2016092308 %y ...
- libs/tools.js stringToDate dateToString 日期字符串转换函数
libs/tools.js stringToDate dateToString 日期字符串转换函数 import { stringToDate } from '@/libs/tools.js' e ...
- js中ajax连接服务器open函数的另外两个默认参数get请求和默认异步(open的post方式send函数带参数)(post请求和get请求区别:get:快、简单 post:安全,量大,不缓存)(服务器同步和异步区别:同步:等待服务器响应当中浏览器不能做别的事情)(ajax和jquery一起用的)
js中ajax连接服务器open函数的另外两个默认参数get请求和默认异步(open的post方式send函数带参数)(post请求和get请求区别:get:快.简单 post:安全,量大,不缓存)( ...
随机推荐
- JavaScript 事件代理绑定
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- kettle 递归循环
var i = new Number(parent_job.getVariable(; parent_job.setVariable("i",i); true;
- linux下apache2更换目录
修改apache2的默认文档目录(默认是在/var/www) 修改命令:sudo gedit /etc/apache2/sites-enabled/000-default 在文档中找到 Documen ...
- Mycat分表分库
一.Mycat介绍 Mycat 是一个开源的分布式数据库系统,是一个实现了 MySQL 协议的的Server,前端用户可以把它看作是一个数据库代理,用 MySQL 客户端工具和命令行访问,而其后端可以 ...
- C++ exit 与 return 浅析
[摘要] 本文从代码形式.经常使用方式,相关概念,调用关系和比較分析,这5个维度浅析 exit 与 return 在C++的同样点与差别. [常见形式] exit(0): 正常执行程序并退出程序. ...
- 【j2ee spring】44、巴巴运动网前台产品显示
[j2ee spring]44.巴巴运动网前台产品显示 项目结构 项目代码 界面显示 <%@ page language="java" isELIgnored="f ...
- 2015年趋势科技笔试A卷
题目原题来源:url=BHz9dr7Dbql5Ai0fTaUsi8QH-ieA9UAtw8kpf-Us_cGUnsz7ZIU1SfHIp33Cphcp0n6uPikWL6r8n0a0zQ0wNOMLG ...
- SRM 621 D2L3: MixingColors, math
题目:http://community.topcoder.com/stat? c=problem_statement&pm=10409&rd=15854 利用高斯消元求线性空间的基,也 ...
- 0x56 状压DP
gan这两题怎么差不多 #include<cstdio> #include<iostream> #include<cstring> #include<cstd ...
- Php learn note
Php learn note 1. Between two part of ECHO, there is , sign rather than + sign. echo 'Hello World!!' ...