js格式化时间 js格式化时间戳
一个js格式化时间和js格式化时间戳的例子。
代码:
/**
* 时间对象的格式化;
*/
Date.prototype.format = function(format) {
/*
* eg:format="YYYY-MM-dd hh:mm:ss";
*/
var o = {
"M+" :this.getMonth() + 1, // month
"d+" :this.getDate(), // day
"h+" :this.getHours(), // hour
"m+" :this.getMinutes(), // minute
"s+" :this.getSeconds(), // second
"q+" :Math.floor((this.getMonth() + 3) / 3), // quarter
"S" :this.getMilliseconds()
// millisecond
} // www.jbxue.com
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;
}
var now = new Date().format("yyyy-MM-dd hh:mm:ss");
new Date().format("yy-MM-dd hh:mm");
js格式化时间 js格式化时间戳的更多相关文章
- Python获取当前时间_获取格式化时间_格式化日期
Python获取当前时间_获取格式化时间: Python获取当前时间: 使用 time.time( ) 获取到距离1970年1月1日的秒数(浮点数),然后传递给 localtime 获取当前时间 #使 ...
- js 日期时间的格式化
将日期时间转换为指定格式,如:YYYY-mm-dd HH:MM表示2019-06-06 19:45 function dateFormat(fmt, date) { let ret; let opt ...
- js中将时间字符串转换为时间戳
var time = "2017-4-18 09:18"; ; console.info(date);
- js时间格式化工具,时间戳格式化,字符串转时间戳
在开发中经常会用到时间格式化,有时候在网上搜索一大堆但不是自己想要的,自己总结一下,写一个时间格式化工具方便以后直接使用,欢迎大家来吐槽…… 1 2 3 4 5 6 7 8 9 10 11 12 13 ...
- js 获取当前时间并格式化
js 获取当前时间并格式化 CreateTime--2018年2月7日11:04:16 Author:Marydon 方式一 /** * 获取系统当前时间并格式化 * @returns yyyy- ...
- js Date 时间格式化的扩展
js Date 时间格式化的扩展: Date.prototype.format = function (fmt) { var o = { , //月 "d+": this.getD ...
- js格式化时间的方法
方法一:用js格式化时间的方法. Date.prototype.format =function(format) { var o = { "M+" : this.getMonth( ...
- js 格式化时间日期函数小结
下面是脚本之家为大家整理的一些格式化时间日期的函数代码,需要的朋友可以参考下. 代码如下: Date.prototype.format = function(format){ var o = { &q ...
- JS格式化时间并比较
JS格式化时间,然后进行比较.工作遇到的情况,然后网上找到的,记下来,下次用! </head> <body> <button onclick="myFuncti ...
随机推荐
- <<网络是怎样连接的>>笔记第5章 防火墙,缓存服务器
第5章 服务器防火墙,缓存服务器 部署地点 防火墙结构和原理 通过将请求平均分配给多台服务器来平衡负载 利用缓存服务器分担负载(客户端也可以部署缓存服务器, 缓存服务器用法很多) 内容分发服务(从缓存 ...
- **优化--后端**: 计数缓存counter_cache; rack-mini-profiler(2300🌟) ; bullet(5000✨):侦测N+1query
rack-mini-profiler 这个 gem,可以永远显示网页的加载时间.(2300✨)开发环境和产品环境都可以用.(生成非常详细的报告) development环境,直接使用gem 'rack ...
- wikioi 1028 花店橱窗布置 最大权匹配
中文题意不描述. 链接:http://wikioi.com/problem/1028/ 这题一开始很裸的最大权二分匹配.但是原来没有接触过,KM的这个最大权不大会.然后一开始以为用最大费用最大流直接就 ...
- oracle增加sequence
(1)删除序列; (2)重新创建: 这个方法比较简单粗暴. drop sequence sequence_name; create sequence sequence_name minvalu ...
- History of programming language
1940之前 第一个编程语言比现代的计算机还早诞生.首先,这种语言是种编码(en:code). 于1801年发明的提花织布机(或称甲卡提花织布机,英文:en:Jacquard loom),运用打孔卡上 ...
- IO综合练习--文件切割和文件合并
有时候一个视频文件或系统文件太大了,上传和下载可能会受到限制,这时可以用文件切割器把文件按大小切分为文件碎片, 等到要使用这个文件了,再把文件碎片合并成原来的文件即可.下面的代码实现了文件切割和文件合 ...
- bzoj 2212 Tree Rotations
bzoj 2212 Tree Rotations 考虑一个子树 \(x\) 的左右儿子分别为 \(ls,rs\) .那么子树 \(x\) 内的逆序对数就是 \(ls\) 内的逆序对数,\(rs\) 内 ...
- 《DSP using MATLAB》Problem 2.15
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 新手,Visual Studio 2013 配置Boost库,如何编译和选择
QuantLib installation in VC++ 2010 and later 参考:http://quantlib.org/install/vc10.shtml 1,到官网下载最新的boo ...
- goaccess nginx日志分析工具简单使用
goaccess 是一个比较方便的支持实时的日志分析工具,比较方便,同时安装&&配置简单 安装 centos yum yum install -y goaccess 运行 我的ngin ...