Recently done project, encountered time conversion problem. Time control, the time format returned is in UTC format.
Next, because you have to do two time to compare. So I thought of a variety of ways.
Through the test, wrote a JS converter. To achieve conversion to normal format (YYYY-MM-DD)
The JS code is as follows: In fact, it is through the string array in the way of stitching into normal format.
function convertdate (UTCSTR) {//tue May 5 0:00:00 utc+0800 ""; var date= "";//month var month=new Array () month["Jan"]=01;month["Feb"]=02;month["Mar"]=03;month["APR"]=04; month["may"]=05;month["Jan"]=06; month["Jul"]=7;month["]=8;month[" Sep "]=9;month[" Oct "]=10;month[" Nov "]=11;month[" Dec "]=12;//week var week=new Array (); week["Mon"]= "one"; week["Tue"]= "two" week["Wed"]= "three" week["Thu"]= "four" week["Fri"]= "five" week["Sat"]= "Six" week["Sun"]= "Day ";//String Stitching str=utcstr.split (" "); date=str[5]+ "-"; 2015-05-05 00:00:00 format date=date+month[str[1]]+ "-" +str[2]+ "" +str[3 "; 2015-05-05 format //date=date+month[str[1]]+ "-" +str[2]; Date=date+ "Week" +week[str[0]]; return date;}
The next step is to compare the size of the time in the two UTC format.
var tcf=convertdate (DT.CFRQ). Split ('-'); var tdd=convertdate (DT.DDRQ). Split ('-'); var sdate=new Date (tcf[0],tcf[1],tcf[2]); var edate=new Date (tdd[0],tdd[1],tdd[2]); if (Sdate.gettime () <=edate.gettime ()) { return true; } else { alert (' Arrival date should be greater than or equal to the departure date '); return false; }
UTC time is converted to normal time and compared to two time