admin管理员组文章数量:1197761
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.
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.
Share Improve this question edited Apr 10, 2013 at 7:10 Ben 52.9k36 gold badges132 silver badges153 bronze badges asked Apr 8, 2013 at 12:10 MonicaMonica 6154 gold badges12 silver badges31 bronze badges 2- re: duplicate. doesn't seem to be a dupe to me (though related is different). – Michael Durrant Commented Apr 8, 2013 at 12:15
- Where does this date? It is a string or a date object? – Shankar Cabus Commented Apr 8, 2013 at 12:32
2 Answers
Reset to default 22You 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";
you can use .replace
var xDate="12:35:45";
alert(xDate.replace(":"," hrs, ").replace(":"," Min and ") + " secs.");
DEMO
本文标签: javascriptSplit time into hoursminutes and secondsStack Overflow
版权声明:本文标题:javascript - Split time into hours, minutes and seconds - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738561938a2099403.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论