Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

difference between two time

// start time and end time
var startTime = moment('12:16:59 am', 'HH:mm:ss a');
var endTime = moment('06:12:07 pm', 'HH:mm:ss a');

// calculate total duration
var duration = moment.duration(endTime.diff(startTime));

// duration in hours
var hours = parseInt(duration.asHours());

// duration in minutes
var minutes = parseInt(duration.asMinutes()) % 60;

alert(hours + ' hour and ' + minutes + ' minutes.');
Comment

PREVIOUS NEXT
Code Example
Javascript :: electron js web reference to use node 
Javascript :: random number in js 
Javascript :: create global variable inside function JavaScript 
Javascript :: apps script get last row with data 
Javascript :: how to compare previous value with current in javascript 
Javascript :: lexical scope javascript 
Javascript :: js run command in terminal 
Javascript :: encrypt js 
Javascript :: sort algorithm for array of objects in js 
Javascript :: why geting empty array from mongodb 
Javascript :: convert string to int javascript 
Javascript :: js number padding to number of characters 
Javascript :: node js express session expiration 
Javascript :: mongoose in nodem js 
Javascript :: javascript how to do if else 
Javascript :: javascript date to html date input 
Javascript :: Regular Expressions: Extract Matches 
Javascript :: angular custom directive 
Javascript :: form data display javascript 
Javascript :: how to append item to an array in foreach javascript 
Javascript :: aos animation 
Javascript :: selection sort javascript 
Javascript :: next js link 
Javascript :: private route in react js 
Javascript :: create a react app 
Javascript :: smooth scroll react 
Javascript :: settings.json in vscode 
Javascript :: addAndRemoveClassJquery 
Javascript :: mongoose mongodb updateone 
Javascript :: how to use react typed js 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =