angularjs - Angular compare time via variables -
i storing time in variable compare 1 , so, have response ifi variable >14:00 or <14:00 not know (and documenation not support), how store "14:00" in second variable..
var time = ed.datetimeto; var checktime=(??); if (time > checktime) { console.log("time >14:00"); } else console.log("time <14:00!");
any welcome!
you can use following mechanism compare 2 time strings:
function datecompare(time1,time2) { var t1 = new date(); var parts = time1.split(":"); t1.sethours(parts[0],parts[1],parts[2],0); var t2 = new date(); parts = time2.split(":"); t2.sethours(parts[0],parts[1],parts[2],0); // returns 1 if greater, -1 if less , 0 if same if (t1.gettime()>t2.gettime()) return 1; if (t1.gettime()<t2.gettime()) return -1; return 0; }
if have complete date in ed.datetimeto
, can use:
var time = new date(ed.datetimeto); var checktime = new date(ed.datetimeto).sethours('14','00','00',0); //this set time 14:00:00 current day compare if (time > checktime) { console.log("time >14:00"); } else console.log("time <14:00!");
Comments
Post a Comment