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;
        }
    }
    
  • 相关阅读:
    C#-------------枚举
    C#-------------类型构造器
    C#-内存天下
    线程在C#中的使用
    C#遗忘笔记--品味类型
    二分查找算法(C#实现)
    Linq 表达式树
    javascript中的对象
    this绑定的顺序
    弹出对话框
  • 原文地址:https://www.cnblogs.com/joexin/p/8948068.html
Copyright © 2011-2022 走看看