zoukankan      html  css  js  c++  java
  • 项目中用到的js日期函数

    <script type="text/javascript">
        //替换字符串  
        function Replace(str, from, to) {
            return str.split(from).join(to);
        }
        // 日期类型格式成指定的字符串
        function FormatDate(date, format) {
            format = Replace(format, "yyyy", date.getFullYear());
            format = Replace(format, "MM", GetFullMonth(date));
            format = Replace(format, "dd", GetFullDate(date));
            format = Replace(format, "HH", GetFullHour(date));
            return format;
        }
        //js日期字符串转换成日期类型
        function parseDate(dateStr) {
            return new Date(Replace(dateStr, "-", "/"));
        }
        //增加月  
        function AddMonths(date, value) {
            date.setMonth(date.getMonth() + value);
            return date;
        }
        //增加天  
        function AddDays(date, value) {
            date.setDate(date.getDate() + value);
            return date;
        }
        //增加时
        function AddHours(date, value) {
            date.setHours(date.getHours() + value);
            return date;
        }
        //返回月份(两位数)  
        function GetFullMonth(date) {
            var v = date.getMonth() + 1;
            if (v > 9) return v.toString();
            return "0" + v;
        }
    
        //返回日(两位数)  
        function GetFullDate(date) {
            var v = date.getDate();
            if (v > 9) return v.toString();
            return "0" + v;
        }
        //返回时(两位数)
        function GetFullHour(date) {
            var v = date.getHours();
            if (v > 9) return v.toString();
            return "0" + v;
        }
        //比较两个时间
        function compareDate() {
            var mydate = AddDays(parseDate("2012-08-23"), 1);
            var nowdate = new Date();
            if (nowdate.getTime() < mydate.getTime()) {
                return FormatDate(nowdate, "yyyy-MM-dd");
            }
            return FormatDate(mydate, "yyyy-MM-dd");
        }
    </script>
    
  • 相关阅读:
    Druid时序数据库常见问题及处理方式
    常用环境变量配置
    Hadoop学习(四) FileSystem Shell命令详解
    Hadoop学习(二) Hadoop配置文件参数详解
    Hadoop学习(一) Hadoop是什么
    Sqoop帮助文档
    CentOS搭建Sqoop环境
    Zookeeper系列(二) Zookeeper配置说明
    查看sql 作业明细及运行记录
    java性能测试工具 jprofiler
  • 原文地址:https://www.cnblogs.com/junjieok/p/2662133.html
Copyright © 2011-2022 走看看