jquery time validation and conversion to standard format time

Source: Internet
Author: User
Tags time in milliseconds

varTimeobjectutil;/** * @title Time Tool class * @note This type of violation verification returns false * @author {[email protected]} * @date 2013-07-01 * @formatter "2013-07-01 00: 00:00 "," 2013-07-01 "*/Timeobjectutil= {    /** * Gets the current time in milliseconds*/Getcurrentmstime:function() {        varMyDate =NewDate (); returnMydate.gettime (); },    /** * Millisecond turn time format*/Longmstimeconverttodatetime:function(time) {varMyDate =NewDate (time); return  This. Formatterdatetime (mydate); },    /** * Time format turns to milliseconds*/Datetolongmstime:function(date) {varMyDate =Newdate (date); returnMydate.gettime (); },    /** * Formatted date (not including time)*/formatterdate:function(date) {vardatetime =date.getfullyear ()+ "-"//"Year"+ ((date.getmonth () + 1) > 10? (Date.getmonth () + 1): "0" + (date.getmonth () + 1))                + "-"//"Month"+ (Date.getdate () < 10? "0" +date.getdate (): Date. GetDate ()); returndatetime; },    /** * Formatted date (with time "00:00:00")*/FormatterDate2:function(date) {vardatetime =date.getfullyear ()+ "-"//"Year"+ ((date.getmonth () + 1) > 10? (Date.getmonth () + 1): "0" + (date.getmonth () + 1))                + "-"//"Month"+ (Date.getdate () < 10? "0" +date.getdate (): Date. GetDate ())+ "" + "00:00:00"; returndatetime; },    /** formatted to date (including time)*/Formatterdatetime:function(date) {vardatetime =date.getfullyear ()+ "-"//"Year"+ ((date.getmonth () + 1) > 10? (Date.getmonth () + 1): "0" + (date.getmonth () + 1))                + "-"//"Month"+ (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 ()); returndatetime; },    /** Time Comparison {end time is greater than start time}*/Comparedateendtimegtstarttime:function(StartTime, endTime) {return((NewDate (Endtime.replace (/-/g, "/"))) > (NewDate (Starttime.replace (/-/g, "/")))); },    /** * Verify start time rationality {start time cannot be less than current time {X} months}*/Comparerightstarttime:function(month, startTime) {varnow = Formatterdayandtime (NewDate ()); varSMS =NewDate (Starttime.replace (/-/g, "/")); varEMS =NewDate (Now.replace (/-/g, "/")); vartdayms = Month * 30 * 24 * 60 * 60 * 1000; varDvalue = EMS-SMS; if(Dvalue >tdayms) {            return false; }        return true; },    /** * Verify start time rationality {end time cannot be less than current time {X} months}*/Comparerightendtime:function(month, endTime) {varnow = Formatterdayandtime (NewDate ()); varSMS =NewDate (Now.replace (/-/g, "/")); varEMS =NewDate (Endtime.replace (/-/g, "/")); vartdayms = Month * 30 * 24 * 60 * 60 * 1000; varDvalue = SMS-EMS; if(Dvalue >tdayms) {            return false; }        return true; },    /** * Verify start time rationality {end time and start time interval cannot be greater than {X} months}*/Compareendtimegtstarttime:function(month, startTime, endTime) {varSMS =NewDate (Starttime.replace (/-/g, "/")); varEMS =NewDate (Endtime.replace (/-/g, "/")); vartdayms = Month * 30 * 24 * 60 * 60 * 1000; varDvalue = EMS-SMS; if(Dvalue >tdayms) {            return false; }        return true; },    /** * Get Last days [start time and end time value, time forward]*/Getrecentdaysdatetime:function(day) {varDaymstime = Day * 24 * 60 * 60 * 1000; varYesterdatsmstime = This. Getcurrentmstime ()-Daymstime; varStartTime = This. Longmstimeconverttodatetime (Yesterdatsmstime); varPastdate = This. FormatterDate2 (NewDate (startTime)); varNowdate = This. FormatterDate2 (NewDate ()); varobj ={starttime:pastdate, endtime:nowdate}; returnobj; },    /** * Get today [start time and end time value]*/Gettodaydatetime:function() {        varDaymstime = 24 * 60 * 60 * 1000; varTomorrowdatsmstime = This. Getcurrentmstime () +Daymstime; varCurrentTime = This. Longmstimeconverttodatetime ( This. Getcurrentmstime ()); varTermorrowtime = This. Longmstimeconverttodatetime (Tomorrowdatsmstime); varNowdate = This. FormatterDate2 (NewDate (currenttime)); varTomorrowdate = This. FormatterDate2 (NewDate (termorrowtime)); varobj ={starttime:nowdate, endtime:tomorrowdate}; returnobj; },    /** * Get tomorrow [Start time and end time value]*/Gettomorrowdatetime:function() {        varDaymstime = 24 * 60 * 60 * 1000; varTomorrowdatsmstime = This. Getcurrentmstime () +Daymstime; varTermorrowtime = This. Longmstimeconverttodatetime (Tomorrowdatsmstime); varThedayaftertomorrowdatsmstime = This. Getcurrentmstime () + (2 *daymstime); varThedayaftertomorrowtime = This. Longmstimeconverttodatetime (Thedayaftertomorrowdatsmstime); varPastdate = This. FormatterDate2 (NewDate (termorrowtime)); varNowdate = This. FormatterDate2 (NewDate (thedayaftertomorrowtime)); varobj ={starttime:pastdate, endtime:nowdate}; returnobj; }};

jquery time validation and conversion to standard format time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.