zoukankan      html  css  js  c++  java
  • js处理日期的一些整理(js获取给定日期前一天的日期)

     var date = new Date();
     alert(date);//获取当前时间
     alert(date.getFullYear());//获取当前年分
     alert(date.getMonth());//获取月份(获取当前月份要加1)
     alert(date.getDate());//获取当前日期的几号
     alert(date.getDay());//获取当前是星期几
     alert(date.getTime());//获取距离1970/01/01 至今的毫秒
    settime()是向 1970/01/01 08:00:00 添加毫秒,并显示新的日期和时间。
    var
    date = new Date();
    date.setTime(
    24*1000*60*60); document.write(date);//输出Thu Jan 02 1970 08:00:00 GMT+0800 (China Standard Time)
    //获取指定日期后几天(明天)的日期   d是那一天,i是后几天
    function getTomorrow(d, i) {
    var date = new Date(d); var tomorrow_milliseconds = date.getTime() + 1000 * 60 * 60 * 24 * i; var tomorrow= new Date(); tomorrow.setTime(tomorrow_milliseconds); var strYear = tomorrow.getFullYear(); var strDay = tomorrow.getDate(); var strMonth = tomorrow.getMonth() + 1; if (strMonth < 10) { strMonth = "0" + strMonth; } datastr = strYear + "/" + strMonth + "/" + strDay; return datastr; }
    //获取给定日期前几天的日期i传负数即可
  • 相关阅读:
    跟光磊学Python开发-面向对象入门
    插件调用下推操作
    K3Wise老单获取单据行数
    git 添加和删除 global 的 remote.origin.url
    CSV转Excel格式
    java 下载文件
    windows下安装redis并设置自启动
    linxu jdk安装
    Linux安装部署Redis
    CentOS上安装MySQL(使用国内源)
  • 原文地址:https://www.cnblogs.com/shinima/p/4016433.html
Copyright © 2011-2022 走看看