jquery time validation and transformation tools Small example

Source: Internet
Author: User
Tags current time datetime getdate
This article describes the jquery time validation and conversion tool Small example, the need for friends can refer to the copy code code as follows:




var timeobjectutil;


/**


* @title Time Tool class


* @note This class of all violations verify return False


* @author {boonyachengdu@gmail.com}


* @date 2013-07-01


* @formatter "2013-07-01 00:00:00", "2013-07-01"


*/


Timeobjectutil = {


/**


* Gets the number of milliseconds in the current time


*/


getcurrentmstime:function () {


var mydate = new Date ();


return Mydate.gettime ();


},


/**


* Millisecond turn time format


*/


longmstimeconverttodatetime:function (time) {


var mydate = new Date (time);


return This.formatterdatetime (mydate);


},


/**


* Time format turn millisecond


*/


Datetolongmstime:function (date) {


var mydate = new Date (date);


return Mydate.gettime ();


},


/**


* Format date (not including time)


*/


formatterdate:function (date) {


var datetime = Date.getfullyear ()


+ "-"//"Year"


+ ((date.getmonth () + 1) > 10? (Date.getmonth () + 1): "0"


+ (Date.getmonth () + 1))


+ "-"//"Month"


+ (Date.getdate () < 10? "0" + date.getdate (): Date


. GetDate ());


return datetime;


},


/**


* Format date (including time "00:00:00")


*/


formatterdate2:function (date) {


var datetime = 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";


return datetime;


},


/**


* Format date (including time)


*/


formatterdatetime:function (date) {


var datetime = 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 ());


return datetime;


},


/**


* Time Comparison {end time is greater than start time}


*/


comparedateendtimegtstarttime:function (StartTime, endtime) {


return (new Date (Endtime.replace (/-/g, "/")) > (new Date (


Starttime.replace (/-/g, "/")));


},


/**


* Verify start time rationality {start time cannot be less than current time {X} months}


*/


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 start time rationality {end time cannot be less than current time {X} months}


*/


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;


},


/**


* Verify start time is reasonable {The interval between end time and start time cannot be greater than {X} months}


*/


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 value, time forward extrapolation]


*/


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 [start time and end time value]


*/


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 [Start time and end time value]


*/


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;


}


};

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.