Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare time in Angular.js?

Tags:

angularjs

I am have two variable

1)$scope.priviuosLevelCutoffTime like 12:00
2)data.cutOffTime(form json) like 13:00

i want to compare this two times are equal or greater by using anguler js,can anyone explain me?how I can compre?

like image 342
user4758229 Avatar asked May 22 '15 06:05

user4758229


People also ask

Can we compare time in JavaScript?

In JavaScript, we can compare two dates by converting them into numeric values to correspond to their time. First, we can convert the Date into a numeric value by using the getTime() function. By converting the given dates into numeric values we can directly compare them.

How do I compare times in typescript?

Call the getTime() method on each date to get a timestamp. Compare the timestamp of the dates. If a date's timestamp is greater than another's, then that date comes after.

How does HH MM SS compare to Java?

If the time is formatted as HH:mm:ss, this should do the trick: boolean beforeNow = endTime. compareTo( new SimpleDateFormat("HH:mm:ss").


2 Answers

Angular does not provide any such method. You would have to use native JS date objects.

var date1 = Date.parse('01/01/1970 ' + $scope.priviuosLevelCutoffTime+':00')
var date1 = Date.parse('01/01/1970 ' + data.cutOffTime+':00')
//date1>date2

You can do put the variables into $scope if you want to use in template.

like image 192
Neo Avatar answered Nov 05 '22 23:11

Neo


Angular has not providr utilities for Date Time

You can use angular moment instead :- https://github.com/urish/angular-moment

like image 20
Oktaheta Avatar answered Nov 05 '22 23:11

Oktaheta