Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split time into hours, minutes and seconds

I have to split time into hours, minutes and seconds. For example if the time is 09:11:21 . I need it as 09 hrs, 11 min and 21 seconds.

I have two textboxes to enter the punch-in time and break time. After that I want to get the result in a new texbox.The result is calculated by the difference between punchin time and break time.

For example if the punch-in time is 09:00:00 and the breaktime is 01:10:00. I need the result as 07 hrs, 50 min and 00 seconds.

like image 761
Monica Avatar asked Apr 08 '13 12:04

Monica


1 Answers

You can use split()

Live Demo

arr = strDate.split(':')
hour = $.trim(arr[0]) + " hrs";
min = $.trim(arr[1]) + " min";
sec = $.trim(arr[2]) + " seconds";

Edit its better to use parseInt instead of $.trim as @TheJohlin told

Live Demo

strDate = "12 : 40 :12";
arr = strDate.split(':');
hour = parseInt(arr[0]) + " hrs";
min = parseInt(arr[1]) + " min";
sec = parseInt(arr[2]) + " seconds";
like image 185
Adil Avatar answered Oct 13 '22 13:10

Adil