zoukankan      html  css  js  c++  java
  • 记录:工作中用到的Js日期时间方法

    /**
     * 获取当前时间
     */
    function getDate() {
        return new Date();
    }
    
    /**
     * 格式化当前时间
     * @param {*} value 
     */
    function getFormatDate(value) {
        var date = new Date(value);
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        month = month < 9 ? '0'+ month : month
        var day = date.getDate();
        day = day < 9 ? '0'+ day : day
        var hours = date.getHours();
        hours = hours < 9 ? '0'+ hours : hours
        var minutes = date.getMinutes();
        minutes = minutes < 9 ? '0'+ minutes : minutes
        var seconds = date.getSeconds();
        seconds = seconds < 9 ? '0'+ seconds : seconds
        return year + '/' + month + '/' + day + ' ' + hours + ':' + minutes + ":" + seconds;
    }
    
    /**
     * 获取当月第一天
     */
    function getFirstMonthday(){
        var date=new Date();
        var firstmonthday=date.setDate(1);
        return getFormatDate(firstmonthday);
    }
    
    /**
     * 日期比较大小(获取天数)
     */
    function getDays(fday, tday) {
        var fday = new Date(fday);
        var tday = new Date(tday);
        var times = fday.getTime() - tday.getTime();
        var day = times / (1000 * 60 * 60 * 24);
        return parseInt(day)
    }
    
    
    /**
     * 判断是否为同一年
     */
    function isSameYear(s, e) {
        var startyear = "", endyear = "";
        startyear = new Date(s).getFullYear();
        endyear = new Date(e).getFullYear();
        if (endyear != startyear) {
            return true;
        } else {
            return false;
        }
    }
    
  • 相关阅读:
    假期(面试题二)
    假期(面向对象相关)
    假期(模块相关)
    假期(面试题一)
    假期(函数相关)
    最后一个假期
    Django缓存问题
    python pass关键字神奇吗
    python中类变量,成员变量
    python类中self是什么
  • 原文地址:https://www.cnblogs.com/joexin/p/8948068.html
Copyright © 2011-2022 走看看