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 ...
随机推荐
- Android之第三方平台实现多平台分享操作
开发中常常遇到分享操作,当用到多种分享时,如:QQ,微信,微博,短信等,可以借助第三方平台来完成,此博客主要借助mob平台来完成相关操作,当然也可以借助其他平台,如友盟等. 先来看看效果图: 如图看出 ...
- hdu4549矩阵快速幂+费马小定理
转移矩阵很容易求就是|0 1|,第一项是|0| |1 1| |1| 然后直接矩阵快速幂,要用到费马小定理 :假如p是质数,且gcd(a,p)=1,那么 a(p-1)≡1(m ...
- Digitalocean+DNSPod搭建Meteor.js博客Telescope.js
1. 什么是Meteor.js 基于Node.js的一个快速开发平台. 简言之,Node.js>Meteor.js 对等于Ruby>Ruby on Rails的关系. 官网:http:// ...
- js固定表头的实现(转)
原文链接:http://www.th7.cn/web/js/201509/121055.shtml 参考链接:http://www.jb51.net/article/102568.htm 写两个表格, ...
- Scrum立会报告+燃尽图 07
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2289] 版本控制:https://git.coding.net/liuyy08 ...
- react中父组件调用子组件的方法
1.直接使用ref进行获取 import React, {Component} from 'react'; export default class Parent extends Component ...
- Java第七次作业--图形用户界面
Deadline: 2017-5-11 23:00 一.学习要点 认真看书并查阅相关资料,掌握以下内容: 了解GUI开发的相关原理和技巧 熟悉Swint组件的使用 理解事件处理模型 二.作业要求 发布 ...
- ZetCode PyQt4 tutorial custom widget
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- nodejs通过buffer传递数据到前端,前端通过arraybuffer接收数据
以后端传送threejs中的点阵数组为例: 后端: let buffer = Buffer.alloc((points.length + 4) * 4) //points.length + 4:预留前 ...
- vue-cli 本地开发mock数据使用方法
vue-cli 中可以通过配置 proxyTable 解决开发环境的跨域问题,具体可以参考这篇文章: Vue-cli proxyTable 解决开发环境的跨域问题 如果后端接口尚未开发完成,前端开发一 ...