Home > Web Front-end > JS Tutorial > Jquery time validation and conversion tool small example_jquery

Jquery time validation and conversion tool small example_jquery

WBOY
Release: 2016-05-16 17:30:40
Original
974 people have browsed it
Copy code The code is as follows:

var TimeObjectUtil;
/**
* @title 시간 도구 클래스
* @note 이 클래스는 항상 규칙을 위반하며 확인 결과는 false로 반환됩니다
* @author {boonyachengdu@gmail.com}
* @date 2013-07- 01
* @formatter "2013-07-01 00:00:00" , "2013-07-01"
*/
TimeObjectUtil = {
    /**
* 현재 시간을 밀리초 단위로 가져옵니다
*/
    getCurrentMsTime : function() {
        var myDate = new Date();
        return myDate.getTime();
    },
    /**
* 밀리초를 시간 형식으로
*/
    longMsTimeConvertToDateTime : function(time) {
        var myDate = new Date(time);
        return this.formatterDateTime(myDate);
    },
    /**
* 시간 형식을 밀리초로 변환
*/
    dateToLongMsTime : function(date) {
        var myDate = new Date (날짜);
        return myDate.getTime();
    },
    /**
* 날짜 형식(시간 제외)
*/
    formatterDate : function(date) {
        var datetime = date.getFullYear( )
               "-"// "年"
               ((date.getMonth() 1) > 10 ? (date.getMonth() 1) : "0"
                      (date.getMonth( ) 1 ))
                "-"// "월"
               (date.getDate() < 10 ? "0" date.getDate() : 날짜
                      .getDate());
        반환 날짜/시간 ;
    },
    /**
* 날짜 형식(시간 "00:00:00" 포함)
*/
    formatterDate2 : function(date) {
        var datetime = date.getFullYear()
               "-"// "年"
                ((date.getMonth() 1) > 10? (date.getMonth() 1) : "0"
                      (date.getMonth() 1))
               "-"// "월"
              (date.getDate() < 10 ? 0 " date.getDate() : 날짜
                       .getDate()) " " "00:00:00";
        return datetime;
    },
    /**
* Format date (including time)
*/
    formatterDateTime : function(date) {
        var datetime = date.getFullYear()
                "-"// "年"
                ((date.getMonth() 1) > 10 ? (date.getMonth() 1) : "0"
                        (date.getMonth() 1))
                "-"// "月"
                (date.getDate() < 10 ? "0" date.getDate() : date
                        .getDate())
                " "
                (date.getHours() < 10 ? "0" date.getHours() : date
                        .getHours())
                ":"
                (date.getMinutes() < 10 ? "0" date.getMinutes() : date
                        .getMinutes())
                ":"
                (date.getSeconds() < 10 ? "0" date.getSeconds() : date
                        .getSeconds());
        return datetime;
    },
    /**
* Time comparison {the end time is greater than the start time}
*/
    compareDateEndTimeGTStartTime : function(startTime, endTime) {
        return ((new Date(endTime.replace(/-/g, "/"))) > (new Date(
                startTime.replace(/-/g, "/"))));
    },
    /**
* Verify the reasonableness of the start time {the start time cannot be less than {X} months from the current time}
*/
    compareRightStartTime : function(month, startTime) {
        var now = formatterDayAndTime(new Date());
        var sms = new Date(startTime.replace(/-/g, "/"));
        var ems = new Date(now.replace(/-/g, "/"));
        var tDayms = month * 30 * 24 * 60 * 60 * 1000;
        var dvalue = ems - sms;
        if (dvalue > tDayms) {
            return false;
        }
        return true;
    },
    /**
* Verify the reasonableness of the start time {the end time cannot be less than {X} months from the current time}
*/
    compareRightEndTime : function(month, endTime) {
        var now = formatterDayAndTime(new Date());
        var sms = new Date(now.replace(/-/g, "/"));
        var ems = new Date(endTime.replace(/-/g, "/"));
        var tDayms = month * 30 * 24 * 60 * 60 * 1000;
        var dvalue = sms - ems;
        if (dvalue > tDayms) {
            return false;
        }
        return true;
    },
    /**
     * 验证开始时间合理性{结束时间与开始时间的间隔不能大于{X}个月}
     */
    compareEndTimeGTStartTime : function(month, startTime, endTime) {
        var sms = new Date(startTime.replace(/-/g, "/"));
        var ems = new Date(endTime.replace(/-/g, "/"));
        var tDayms = month * 30 * 24 * 60 * 60 * 1000;
        var dvalue = ems - sms;
        if (dvalue > tDayms) {
            return false;
        }
        return true;
    },
    /**
* Get the last few days [start time and end time values, time extrapolated forward]
*/
    getRecentDaysDateTime : function(day) {
        var daymsTime = day * 24 * 60 * 60 * 1000;
        var yesterDatsmsTime = this.getCurrentMsTime() - daymsTime;
        var startTime = this.longMsTimeConvertToDateTime(yesterDatsmsTime);
        var pastDate = this.formatterDate2(new Date(startTime));
        var nowDate = this.formatterDate2(new Date());
        var obj = {
            startTime : pastDate,
            endTime : nowDate
        };
        return obj;
    },
    /**
* Get today’s [start time and end time values]
*/
    getTodayDateTime : function() {
        var daymsTime = 24 * 60 * 60 * 1000;
        var tomorrowDatsmsTime = this.getCurrentMsTime() daymsTime;
        var currentTime = this.longMsTimeConvertToDateTime(this.getCurrentMsTime());
        var termorrowTime = this.longMsTimeConvertToDateTime(tomorrowDatsmsTime);
        var nowDate = this.formatterDate2(new Date(currentTime));
        var tomorrowDate = this.formatterDate2(new Date(termorrowTime));
        var obj = {
            startTime : nowDate,
            endTime : tomorrowDate
        };
        return obj;
    },
    /**
* Get tomorrow’s [start time and end time values]
*/
    getTomorrowDateTime : function() {
        var daymsTime = 24 * 60 * 60 * 1000;
        var tomorrowDatsmsTime = this.getCurrentMsTime() daymsTime;
        var termorrowTime = this.longMsTimeConvertToDateTime(tomorrowDatsmsTime);
        var theDayAfterTomorrowDatsmsTime = this.getCurrentMsTime() (2 * daymsTime);
        var theDayAfterTomorrowTime = this.longMsTimeConvertToDateTime(theDayAfterTomorrowDatsmsTime);
        var pastDate = this.formatterDate2(new Date(termorrowTime));
        var nowDate = this.formatterDate2(new Date(theDayAfterTomorrowTime));
        var obj = {
            startTime : pastDate,
            endTime : nowDate
        };
        return obj;
    }
};
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template