Issue
I have two time without date
var startTime="12:16:59 am";
var endTime="06:12:07 pm";
I want to show the total hours in between the above times by using moment.js.
If it's not possible in moment.js
then please let me know using by javascript
.
Inputs:
var startTime="01:30:00 am";
var endTime="2:45:07 pm";
Expected Output:
1 hour and 15 minutes
Solution
Get Hours
I got the hours by using this code
endTime.diff(startTime, 'hours')
Get Minutes
i got the minutes by using this below code
var mins = moment.utc(moment(endTime, "HH:mm:ss").diff(moment(startTime, "HH:mm:ss"))).format("mm")
My Working code is
$scope.UpdateTimeSheet = function (rowEntity) {
if (rowEntity.StartTime.toString().length != 11) {
rowEntity.StartTime = moment(rowEntity.StartTime).format("hh:mm:ss a");
}
if (rowEntity.EndTime.toString().length != 11) {
rowEntity.EndTime = moment(rowEntity.EndTime).format("hh:mm:ss a");
}
var startTime = moment(rowEntity.StartTime, "hh:mm:ss a");
var endTime = moment(rowEntity.EndTime, "hh:mm:ss a");
var mins = moment.utc(moment(endTime, "HH:mm:ss").diff(moment(startTime, "HH:mm:ss"))).format("mm")
rowEntity.TotalHours = endTime.diff(startTime, 'hours') + " Hrs and " + mins + " Mns";
}
Answered By - Ramesh Rajendran
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.