Avatar of stargateatlantis
stargateatlantis

asked on 

expire time comparing string

I have  the following code that will set a timer to any given label.  The question is I want the ability to pass to this function a expire time to a specific label.  So not comparing times but actual string saying if the time is 00:10:10  then it would change the label to red using jquey. So i am not sure if the timer would need some sort of listener.  On change listener.  
//Timer JQuery function
(function ($) {
   totaltime = "00:00:00";
	$.do_time = function(timerID) {
		
		var time = ($("#" + timerID).html()).split(':');
		var hour = parseInt(time[0], 10);
		var minute = parseInt(time[1], 10);
		var second = parseInt(time[2], 10) + 1;
		
		var ttime = totaltime.split(':');
		var thour = parseInt(ttime[0], 10);
		var tminute = parseInt(ttime[1], 10);
		var tsecond = parseInt(ttime[2], 10) + 1;
		
		if (second > 59) {
			second = 0;
			minute++;
		}
		if (minute > 59) {
			minute = 0;
			hour++;
		}
		if (tsecond > 59) {
			tsecond = 0;
			tminute++;
		}
		if (tminute > 59) {
			tminute = 0;
			thour++;
		}
		
		time = (hour>9?hour:'0'+hour) +':'+ (minute>9?minute:'0'+minute) +':'+ (second>9?second:'0'+second);
		$("#" + timerID).html(time);
		totaltime = "" + (thour>9?thour:'0'+thour) +':'+ (tminute>9?tminute:'0'+tminute) +':'+ (tsecond>9?tsecond:'0'+tsecond);
	} //End Doo time function
	$.displayTotal = function(labelID) {
		$("#" + labelID).html(totaltime);
	}
})(jQuery);

Open in new window

jQueryJavaScript

Avatar of undefined
Last Comment
Samuel Liew

8/22/2022 - Mon