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 date = new Date();
var currDate= date.Format("yyyy-MM-dd hh:mm");
date.setDate(date.getDate()-1);
var prevDate = date.Format("yyyy-MM-dd hh:mm"); console.log(currDate);
console.log(prevDate);

js date 前一天的更多相关文章

  1. JS计算前一天或后一天,前一月后一月

    JS计算前一天或后一天,前一月后一月,上一天下一下,上一月下一月. 方法一: function ktkGetNextMonth(currentDate, scaleStep) { //scaleSte ...

  2. 使用JS计算前一天和后一天

    使用JS实现前一天和后一天 首先,我们先在html中写两个按钮来进行简单操作 <button onclick="Before()">前一天</button> ...

  3. JS Date当前时间:获取日期时间方法在各浏览器中的差异

    转自:http://www.feiesoft.com/00047/<script type="text/javascript"> // JS Date当前时间获取方法在 ...

  4. js Date 时间格式化的扩展

    js Date 时间格式化的扩展: Date.prototype.format = function (fmt) { var o = { , //月 "d+": this.getD ...

  5. Js Date泣血整理

    原文:Js Date泣血整理 JS Date 对象用于处理日期和时间. 创建 Date 对象的语法: var myDate=new Date() Date 对象会自动把当前日期和时间保存为其初始值. ...

  6. js Date对象总结

    Date在js中和Array类似,都是拥有自己的特殊方法的特殊对象. 由于平常用到Date着实不多,对它的了解颇浅.上周被问到怎么样获取某年某个月的天数,我当时想了一会儿,回答说有两种,一种自己写判断 ...

  7. js Date 函数方法及日期计算

    js Date 函数方法 var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整的年份 ...

  8. 扩展JS Date对象时间格式化功能

    在自己JS代码中引入一下代码: Date.prototype.format =function(format) { var o = { "M+" : this.getMonth() ...

  9. JS date常用代码积累

    Date.prototype.Format = function(fmt) { var o = { "M+" : this.getMonth()+1, //月份 "d+& ...

随机推荐

  1. 2017-9-12-Linux移植&驱动开发

    准备学习Linux很长时间了,很大的一个原因就是兴趣,Linux对科技进步发展.人们生活的改变影响之深很难用简简单单的一些话描述清楚.跟Linux密切相关的东西,开源软件.c语言.底层驱动.网络.服务 ...

  2. python3.6.5 + selenium +VS Code 运行报错:Unable to find a matching set of capabilities的解决

    在python3.6.5 + selenium +VS Code 环境中,在class的__init__ 方法初始化火狐浏览器时出现以下错误: 发生异常: selenium.common.except ...

  3. token和盐

    // 盐,加密后密码获取    Map<String, String> map = new HashMap<String, String>();    map.put(&quo ...

  4. HDU 5961 传递 随机化

    传递 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5961 Description 我们称一个有向图G是传递的,当且仅当对任意三个不同的顶点a,,若 ...

  5. Mac安装Linux的KVM管理工具virt-manager

    安装: brew tap jeffreywildman/homebrew-virt-manager brew install virt-manager virt-viewer 中途会碰到很多问题,可以 ...

  6. MOS管当开关控制时,为什么一般用PMOS做上管NMOS做下管?

    了解MOS管的开通/关断原理你就会发现,使用PMOS做上管.NMOS做下管比较方便.使用PMOS做下管.NMOS做上管的电路设计复杂,一般情况下意义不大,所以很少采用. 下面先了解MOS管的开通/关断 ...

  7. Gcode命令【转】

    https://www.jianshu.com/p/f8a328457a45 简述 研究过3D打印机的朋友,都会用到G-code文件.要使用3D打印机打印东西要经过几个步骤:        1.创建3 ...

  8. NLP 第10章 基于深度学习的NLP 算法

  9. Mongodb: Sort operation used more than the maximum 33554432 bytes of RAM

    上线许久的产品突然爆出了一个Mongodb 查询的BUG,错误如下: "exception":"org.springframework.data.mongodb.Unca ...

  10. notepad++使用收集

    一. 列编辑: 按住alt+鼠标纵向选中:alt+shift+箭头纵向或者横向选中. 列块编辑(编辑->列块编辑),实现跨步增加数字写入或者补0写入. 二. 多行变一行: 1.按Ctrl+F,弹 ...