//js格式化时间 "yyyy-MM-dd hh:mm:ss"
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;
}
Date.prototype.addDays = function (d) {
this.setDate(this.getDate() + d);
};
Date.prototype.addWeeks = function (w) {
this.addDays(w * 7);
};
Date.prototype.addMonths = function (m) {
var d = this.getDate();
this.setMonth(this.getMonth() + m);
if (this.getDate() < d)
this.setDate(0);
};
Date.prototype.addYears = function (y) {
var m = this.getMonth();
this.setFullYear(this.getFullYear() + y);
if (m < this.getMonth()) {
this.setDate(0);
}
};
var now = new Date();
now.addDays(1);//加减日期操作
alert(now.Format("yyyy-MM-dd"));

js 时间加减的更多相关文章

  1. js时间加减

    1.选择上一周方法(不算当天) $("#weekSel").click(function () { //当前时间 var now = new Date(); //当前时间往前推一周 ...

  2. js时间比较大小,时间加减

    第一种: //时间类比较 startTime= new Date(Date.parse(starttime)); endTime=new Date(Date.parse(endTime)); //进行 ...

  3. JAVA时间进行比较和转换,时间加减得到天数

    转自:https://blog.csdn.net/iteye_8535/article/details/82246006 JAVA时间进行比较和转换,时间加减得到天数 1. 把时间类型的字符串转为DA ...

  4. Sql里时间加减

    简单的时间加减 DATEADD(dd,-30, GETDATE())) 使用DateADD方法: 参数1:间隔,表示要添加的时间间隔,一天还是一月还是一年 参数2:要加或减的个数,加一年或加一月 参数 ...

  5. DB2时间函数 实现 时间加减

    时间加减:后边记得跟上时间类型如day.HOUR TIMESTAMP ( TIMESTAMP(DEF_TIME)+1 day)+18 HOUR   DB2时间函数是我们最常见的函数之一,下面就为您介绍 ...

  6. JS日期时间加减实现

    首先,上代码 var diffDate = function(date, diff) { return new Date( Date.UTC( date.getUTCFullYear(), date. ...

  7. JS日期加减指定天数

    JS中没有直接操作日期加减的方法,只能通过Date对象获取当前天数加减之后setDate,以此来达到操作日期的目的 JS中对指定日期加减指定天数,具体方法如下: function addDate(da ...

  8. php 时间加减

    <?php date_default_timezone_set('PRC'); //默认时区 echo "今天:",date("Y-m-d",time() ...

  9. php如何在某个时间上加一天?一小时? 时间加减

    <?php date_default_timezone_set('PRC'); //默认时区 echo "今天:",date("Y-m-d",time() ...

随机推荐

  1. CRC8算法DELPHI源码

    unit Crc8; interface Uses Classes, Windows; Function Crc_8n(p : array of BYTE; len : BYTE) : Byte; i ...

  2. 学习 HTML+CSS 的书籍推荐

    1.<CSS那些事儿> 本书专注于CSS技巧实例的讲解,由浅入深地分析了CSS样式在布局时所需要理解的原理.绕开随处可见的基础知识.网络中能随意搜索到的hack技巧,侧重原理分析,拓展读者 ...

  3. C#+arcengine获得栅格数据的像素值(高程)

    此文问获得栅格数据的像元值(即高程),有可能部分见解不到位,望大神看到了不惜指教! /// <summary> ///  得到高程(通过像素值)         /// </summ ...

  4. 【mybatis】【mysql】mybatis查询mysql,group by分组查询报错:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column

    mybatis查询mysql,group by分组查询报错:Expression #1 of SELECT list is not in GROUP BY clause and contains no ...

  5. 倒计时相关函数 php

    <script type="text/javascript" language="javascript"> function datetime_to ...

  6. 自定义各式各样的圆形ProgressBar

         上面三个图分别是 开始时的样子,走进度时候的样子,最后完成的样子 这是我在两个大神的Demo基础上修改后的结果,我们先来看看自定义view是怎么做到的. 1.自己写一个类继承View类,然后 ...

  7. Gallery和自定义Adapter配合使用,实现图片预览

    Gallery是一个可以拖动的列表,正中对应的是选中的东西.他和spinner有共同的父类:AbsSpinner 属性: android:animationDuration="1000&qu ...

  8. 【BZOJ】【3930】【CQOI2015】选数

    数论/莫比乌斯反演/快速mu前缀和 比较容易想到令f[x]表示gcd=x的方案数,令g[x]表示x|gcd的方案数. 那么有$ g(d)=\sum_{d|n} f(n)$,根据莫比乌斯反演,有$f(d ...

  9. SQL Script for select data from ebs and make a csv file to FTP

    DECLARE CURSOR cur_lcy_test IS SELECT rcta.customer_trx_id, rcta.trx_number, rcta.trx_date FROM ra_c ...

  10. @Tomcat中的几种log

    日志是程序员居家旅行必备,哦不对,是定位问题,修复bug,甚至是验证应用是否正常的必备利器.甚至很多时候,我们做一次部署仅仅是为了加一行log.虽然现在有各种各样的问题诊断工具,但是在定位线上问题时, ...