zoukankan      html  css  js  c++  java
  • js--------js获取当前时间,返回日期yyyy-MM-dd

     1 //获取当前时间 yyyy-MM-dd
     2 function getNowFormatDate() {
     3     var date = new Date();
     4     var seperator1 = "-";
     5     var seperator2 = ":";
     6     var month = date.getMonth() + 1;
     7     var strDate = date.getDate();
     8     if (month >= 1 && month <= 9) {
     9         month = "0" + month;
    10     }
    11     if (strDate >= 0 && strDate <= 9) {
    12         strDate = "0" + strDate;
    13     }
    14     var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
    15     return currentdate;
    16 }
     1 //获取当前日期,个位数用0占位
     2 function getNowWithLine() {
     3     var date = new Date();
     4     var seperator1 = "/";
     5     var seperator2 = ":";
     6     var month = date.getMonth() + 1;
     7     var strDate = date.getDate();
     8     if (month >= 1 && month <= 9) {
     9         month = "0" + month;
    10     }
    11     if (strDate >= 0 && strDate <= 9) {
    12         strDate = "0" + strDate;
    13     }
    14     var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
    15     return currentdate;
    16 }
     1 //获取指定日期的前几天日期或后几天日期
     2 function getDateFromCurrentDate(fromDate, dayInterval) {
     3 
     4     var curDate = new Date(Date.parse(fromDate.replace(/-/g, "/")));
     5     curDate.setDate(curDate.getDate() + dayInterval);
     6     var year = curDate.getFullYear();
     7     var month = (curDate.getMonth() + 1) < 10 ? "0" + (curDate.getMonth() + 1) : (curDate.getMonth() + 1);
     8     var day = curDate.getDate() < 10 ? "0" + curDate.getDate() : curDate.getDate();
     9     return year + "-" + month + "-" + day;
    10 };
     1 //当前日期加n天 返回日期 yyyy-MM-dd
     2 function getFormatDate(addDay) {
     3     var date = new Date();
     4     date.setDate(date.getDate() + addDay);
     5     var seperator1 = "-";
     6     var month = date.getMonth() + 1;
     7     var strDate = date.getDate();
     8     if (month >= 1 && month <= 9) {
     9         month = "0" + month;
    10     }
    11     if (strDate >= 0 && strDate <= 9) {
    12         strDate = "0" + strDate;
    13     }
    14     var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
    15     return currentdate;
    16 }
  • 相关阅读:
    WebClient 非阻塞客户端 RestTemplate 阻塞式客户端
    微服务网关---调用其他微服务
    复习下comparable和comparator以及比较
    关于InitializingBean的用法、应用
    Scheduled(cron = "")
    windows查看进程方法(老是忘只能写了)
    vue 控件component
    vue 过滤器的使用实例
    vue基础
    日志脱敏工具
  • 原文地址:https://www.cnblogs.com/chocolatexll/p/9274853.html
Copyright © 2011-2022 走看看