javascript - how to compare 2 times in 24 hour format to check if 1 time is before another time -


i have time strings in 24 hour format 20:50 , 23:00

now want make method in javascript determine if 1 time earlier othertime. have done in php so:

function islater($time1, $time2) { $time1 = new datetime($time1); $time2 = new datetime($time2);  if ($time1 > $time2) { return true; } return false; }  function isearlier($time1, $time2) {     $time1 = new datetime($time1);     $time2 = new datetime($time2);      if ($time1 < $time2) {     return true;     }     return false; } 

my question is, best approach in javascript?

using same structure have done in php, this:

function islater(time1, time2) {   if (time1 > time2) {     return true;   }   return false; }  function isearlier(time1, time2) {   if (time1 < time2) {     return true;   }   return false; } 

because javascript consider "a" less "b" , "2" less "3", there no need convert datetime.

if want make code shorter, make function this:

function islater(time1, time2) {   return time1 > time2; }  function isearlier(time1, time2) {   return time1 < time2; } 

this shorter version work in php (assuming add $ signs variables).


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -