加:
console.log(moment().format("YYYY-MM-DD HH:mm:ss")); //当前时间
console.log(moment().add(10, "days").format("YYYY-MM-DD")); //当前时间的后10天时间
console.log(moment().add(1, "years").format("YYYY-MM-DD")); //当前时间的后1年时间
console.log(moment().add(3, "months").format("YYYY-MM-DD")); //当前时间的后3个月时间
console.log(moment().add(1, "weeks").format("YYYY-MM-DD")); //当前时间的后一个星期时间

减:
console.log(moment().format("YYYY-MM-DD HH:mm:ss")); //当前时间
console.log(moment().subtract(10, "days").format("YYYY-MM-DD")); //当前时间的前10天时间
console.log(moment().subtract(1, "years").format("YYYY-MM-DD")); //当前时间的前1年时间
console.log(moment().subtract(3, "months").format("YYYY-MM-DD")); //当前时间的前3个月时间
console.log(moment().subtract(1, "weeks").format("YYYY-MM-DD")); //当前时间的前一个星期时间

参考https://majing.io/posts/10000006081171

js 日期加减的更多相关文章

  1. JS日期加减指定天数

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

  2. js日期加减

    先补充下基础知识: var myDate = new Date(); //myDate默认返回当前时间 myDate.getYear(); //获取当前年份(2位) myDate.getFullYea ...

  3. Js 日期加减天数

    <SCRIPT language="javascript"> function addDate(dd,dadd){ var a = new Date(dd) a = a ...

  4. JS日期加减,日期运算

    一.日期减去天数等于第二个日期 function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 ...

  5. 转:JS日期加减,日期运算

    原文 出处http://hi.baidu.com/tonlywang/item/685fba8933a2a756e73d1950 一.日期减去天数等于第二个日期 function cc(dd,dadd ...

  6. js中两个日期大小比较,获取当前日期,日期加减一天

    一.两个日期大小比较 1.日期参数格式:yyyy-mm-dd // a: 日期a, b: 日期b, flag: 返回的结果 function duibi(a, b,flag) { var arr = ...

  7. JavaScript日期加减

    JS中的日期加减使用以下方式: varcurrentDate = new Date(); 对日期加减: date.setDate(date.getDate()+n); 对月加减: date.setMo ...

  8. Delphi日期函数、日期加减

    Delphi里有现成的函数可以实现日期加减,是在DateUtils单元里的. function IncYear(const AValue: TDateTime; const ANumberOfYear ...

  9. java 和 mysql 获取周 星期 的第一天 最后一天 或者 月的 日期(字符串转日期,日期转字符串,日期加减)

    获取周的第一天,最后一天 System.out.println(getStartEndDate("2016-05-01", 1)); 获取星期的第一天和最后一天 System.ou ...

随机推荐

  1. bob and brad physical therapy knee exercise

    bob and brad physical therapy knee exercise 鲍勃和布拉德物理治疗膝关节运动 https://bobandbrad.com/ youtube https:// ...

  2. img & srcset

    img & srcset 性能优化 <img class="fn tj s t u fa ai ht" width="3700" height=& ...

  3. free online code editor

    free online code editor online vscode https://stackblitz.com/ https://codesandbox.io/ https://codesh ...

  4. LGTM & code review

    LGTM & code review LGTM is an acronym meaning looks good to me, frequently used when reviewing d ...

  5. CSS Shapes

    CSS Shapes shape-outside & shape-image-threshold <img class="element" src="ima ...

  6. vue & $router & History API

    vue & $router gotoTemplateManage(e) { e.preventDefault(); this.$router.push({ path: `/operate-to ...

  7. nasm aat函数 x86

    xxx.asm: %define p1 ebp+8 %define p2 ebp+12 %define p3 ebp+16 section .text global dllmain dllmain: ...

  8. Flutter: ValueListenableBuilder 内容与ValueListenable保持"同步"的窗口小部件

    API 使用这个修改状态可以不用setState(). class _MyHomeState extends State<MyHome> { final ValueNotifier< ...

  9. Masterboxan INC 下半年将聚焦超高净值和家族全权委托客户

    "投资是一个没有终点的奋斗.我们不能简单的预测市场,而是应对市场做出正确的反应.这需要我们不断反思.总结.提升,找到自己的投资哲学,然后用一生的时间去坚守."Masterboxan ...

  10. 手把手教你使用IDEA2020创建SpringBoot项目

    一.New Project 二.如图选择Spring Initalizr,选择jdk版本,然后点击Next(注意:SpringBoot2开始至少使用JDK1.8) 三.如图根据自己需要修改,然后点击N ...