js date 前一天
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 前一天的更多相关文章
- JS计算前一天或后一天,前一月后一月
JS计算前一天或后一天,前一月后一月,上一天下一下,上一月下一月. 方法一: function ktkGetNextMonth(currentDate, scaleStep) { //scaleSte ...
- 使用JS计算前一天和后一天
使用JS实现前一天和后一天 首先,我们先在html中写两个按钮来进行简单操作 <button onclick="Before()">前一天</button> ...
- JS Date当前时间:获取日期时间方法在各浏览器中的差异
转自:http://www.feiesoft.com/00047/<script type="text/javascript"> // JS Date当前时间获取方法在 ...
- js Date 时间格式化的扩展
js Date 时间格式化的扩展: Date.prototype.format = function (fmt) { var o = { , //月 "d+": this.getD ...
- Js Date泣血整理
原文:Js Date泣血整理 JS Date 对象用于处理日期和时间. 创建 Date 对象的语法: var myDate=new Date() Date 对象会自动把当前日期和时间保存为其初始值. ...
- js Date对象总结
Date在js中和Array类似,都是拥有自己的特殊方法的特殊对象. 由于平常用到Date着实不多,对它的了解颇浅.上周被问到怎么样获取某年某个月的天数,我当时想了一会儿,回答说有两种,一种自己写判断 ...
- js Date 函数方法及日期计算
js Date 函数方法 var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整的年份 ...
- 扩展JS Date对象时间格式化功能
在自己JS代码中引入一下代码: Date.prototype.format =function(format) { var o = { "M+" : this.getMonth() ...
- JS date常用代码积累
Date.prototype.Format = function(fmt) { var o = { "M+" : this.getMonth()+1, //月份 "d+& ...
随机推荐
- redis(二)
基本配置 在源文件/usr/local/redis目录下,文件redis.conf为配置文件 绑定地址:如果需要远程访问,可将此行注释 bind 127.0.0.1 端口,默认为6379 port 6 ...
- 道路 [NOIP模拟]
Description 我们看见了一个由 m 行 n 列的 1*1 的格子组成的矩阵,每个格子(I,j)有对应的高度 h[i][j]和初始的一个非负权值 v[i][j].我们可以随便选择一个格子作为起 ...
- 编程菜鸟的日记-初学尝试编程-编写函数实现strcat
#include <iostream>using namespace std;char *mystrcat(const char *str1,const char *str2){ char ...
- springmvc注解方式
https://www.cnblogs.com/shanheyongmu/p/5865589.html
- yii创建控制台命令
创建控制台命令程序1.控制台命令继承自 yii\console\Controller控制器类2.在控制器类中,定义一个或多个动作,动作与控制台子命令相对应3.在动作方法中实现业务需求的代码 运行控制台 ...
- array中key所对应的value
获取数组中的键对应的值 class Test{ public function index(){ $info = array( 'name' => 'daicr', 'age' => 24 ...
- mysql5.7.20完全卸载 win10
试了好多方法,搞了很久终于完全卸载干净,重装完成了! 1.关闭服务 以管理员身份运行cmd,执行以下命令: C:\WINDOWS\system32>net stop mysql MySQL 服务 ...
- Mac下nodeJS初体验
Mac下nodeJS初体验 这两天博主出门在外,抽空体验一下大名鼎鼎的node 安装 brew install node 安装测试 $ node -v v8.4.0 运行本地脚本 用文本编辑器编辑一段 ...
- 获取html下的所有纯文本的方法
第一种是看别人博客的,第二种是自己发现的. 第一种: #-*- coding: utf8 -*- import re html = """ <div class=& ...
- a^b%p and a*b%p快速幂
#include<cstdio> int power(int a, int b, int p) { %p; ) { ) ans=(long long)ans*a%p; a=(long lo ...