How to get difference between times in decimal in moment js? The Next CEO of Stack OverflowHow do you get a timestamp in JavaScript?How to get the children of the $(this) selector?Difference between == and === in JavaScriptWhat's the difference between using “let” and “var”?How can I get query string values in JavaScript?What is the difference between call and apply?How to decide when to use Node.js?Differences between lodash and underscoreWhat is the difference between Bower and npm?Get hours difference between two dates in Moment Js
How to implement Comparable so it is consistent with identity-equality
Does the Idaho Potato Commission associate potato skins with healthy eating?
logical reads on global temp table, but not on session-level temp table
How can I prove that a state of equilibrium is unstable?
Masking layers by a vector polygon layer in QGIS
How can a day be of 24 hours?
Could a dragon use its wings to swim?
Direct Implications Between USA and UK in Event of No-Deal Brexit
How to coordinate airplane tickets?
Upgrading From a 9 Speed Sora Derailleur?
Find a path from s to t using as few red nodes as possible
Incomplete cube
Another proof that dividing by 0 does not exist -- is it right?
Is it reasonable to ask other researchers to send me their previous grant applications?
Can a PhD from a non-TU9 German university become a professor in a TU9 university?
Is it a bad idea to plug the other end of ESD strap to wall ground?
Finitely generated matrix groups whose eigenvalues are all algebraic
My boss doesn't want me to have a side project
Early programmable calculators with RS-232
How dangerous is XSS
Mathematica command that allows it to read my intentions
Could you use a laser beam as a modulated carrier wave for radio signal?
Is this a new Fibonacci Identity?
Why was Sir Cadogan fired?
How to get difference between times in decimal in moment js?
The Next CEO of Stack OverflowHow do you get a timestamp in JavaScript?How to get the children of the $(this) selector?Difference between == and === in JavaScriptWhat's the difference between using “let” and “var”?How can I get query string values in JavaScript?What is the difference between call and apply?How to decide when to use Node.js?Differences between lodash and underscoreWhat is the difference between Bower and npm?Get hours difference between two dates in Moment Js
How to get the difference between times in decimal in moment js?
For example: in: '17:39', out: '21:10'.
I try to do this code but it's not work for me:
let startTime = project[0].in;
let end = project[0].out;
startTime = moment(startTime, ['H:m']);
end = moment(end, ['H:m']);
var duration = moment.duration(end.diff(startTime));
var hours = duration.asHours();
var minutes = parseInt(duration.asMinutes()) % 60;
console.log( hours, minutes );
const a = duration.asMinutes(); //moment.duration('1:30').asHours();
console.log( a );
javascript momentjs
add a comment |
How to get the difference between times in decimal in moment js?
For example: in: '17:39', out: '21:10'.
I try to do this code but it's not work for me:
let startTime = project[0].in;
let end = project[0].out;
startTime = moment(startTime, ['H:m']);
end = moment(end, ['H:m']);
var duration = moment.duration(end.diff(startTime));
var hours = duration.asHours();
var minutes = parseInt(duration.asMinutes()) % 60;
console.log( hours, minutes );
const a = duration.asMinutes(); //moment.duration('1:30').asHours();
console.log( a );
javascript momentjs
add a comment |
How to get the difference between times in decimal in moment js?
For example: in: '17:39', out: '21:10'.
I try to do this code but it's not work for me:
let startTime = project[0].in;
let end = project[0].out;
startTime = moment(startTime, ['H:m']);
end = moment(end, ['H:m']);
var duration = moment.duration(end.diff(startTime));
var hours = duration.asHours();
var minutes = parseInt(duration.asMinutes()) % 60;
console.log( hours, minutes );
const a = duration.asMinutes(); //moment.duration('1:30').asHours();
console.log( a );
javascript momentjs
How to get the difference between times in decimal in moment js?
For example: in: '17:39', out: '21:10'.
I try to do this code but it's not work for me:
let startTime = project[0].in;
let end = project[0].out;
startTime = moment(startTime, ['H:m']);
end = moment(end, ['H:m']);
var duration = moment.duration(end.diff(startTime));
var hours = duration.asHours();
var minutes = parseInt(duration.asMinutes()) % 60;
console.log( hours, minutes );
const a = duration.asMinutes(); //moment.duration('1:30').asHours();
console.log( a );
javascript momentjs
javascript momentjs
asked Mar 8 at 19:22
Jon SudJon Sud
327
327
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I'm not totally sure what your expected output should be in your example, maybe the following code will help you.
const moment = require('moment');
const start = moment('21:10', 'HH:mm');
const end = moment('17:39', 'HH:mm');
const difference = start.diff(end);
const duration = moment.duration(difference);
const minutes = duration.asMinutes() % 60;
const hours = Math.floor(duration.asMinutes() / 60);
console.log(hours + ':' + minutes); // 3:31
Thanks but how to covert to decimal?
– Jon Sud
Mar 8 at 19:43
duration.asHours()
is in decimal. Could you give an example of your expected output?
– Michiel
Mar 8 at 20:01
add a comment |
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069681%2fhow-to-get-difference-between-times-in-decimal-in-moment-js%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm not totally sure what your expected output should be in your example, maybe the following code will help you.
const moment = require('moment');
const start = moment('21:10', 'HH:mm');
const end = moment('17:39', 'HH:mm');
const difference = start.diff(end);
const duration = moment.duration(difference);
const minutes = duration.asMinutes() % 60;
const hours = Math.floor(duration.asMinutes() / 60);
console.log(hours + ':' + minutes); // 3:31
Thanks but how to covert to decimal?
– Jon Sud
Mar 8 at 19:43
duration.asHours()
is in decimal. Could you give an example of your expected output?
– Michiel
Mar 8 at 20:01
add a comment |
I'm not totally sure what your expected output should be in your example, maybe the following code will help you.
const moment = require('moment');
const start = moment('21:10', 'HH:mm');
const end = moment('17:39', 'HH:mm');
const difference = start.diff(end);
const duration = moment.duration(difference);
const minutes = duration.asMinutes() % 60;
const hours = Math.floor(duration.asMinutes() / 60);
console.log(hours + ':' + minutes); // 3:31
Thanks but how to covert to decimal?
– Jon Sud
Mar 8 at 19:43
duration.asHours()
is in decimal. Could you give an example of your expected output?
– Michiel
Mar 8 at 20:01
add a comment |
I'm not totally sure what your expected output should be in your example, maybe the following code will help you.
const moment = require('moment');
const start = moment('21:10', 'HH:mm');
const end = moment('17:39', 'HH:mm');
const difference = start.diff(end);
const duration = moment.duration(difference);
const minutes = duration.asMinutes() % 60;
const hours = Math.floor(duration.asMinutes() / 60);
console.log(hours + ':' + minutes); // 3:31
I'm not totally sure what your expected output should be in your example, maybe the following code will help you.
const moment = require('moment');
const start = moment('21:10', 'HH:mm');
const end = moment('17:39', 'HH:mm');
const difference = start.diff(end);
const duration = moment.duration(difference);
const minutes = duration.asMinutes() % 60;
const hours = Math.floor(duration.asMinutes() / 60);
console.log(hours + ':' + minutes); // 3:31
edited Mar 8 at 19:40
answered Mar 8 at 19:34
MichielMichiel
264
264
Thanks but how to covert to decimal?
– Jon Sud
Mar 8 at 19:43
duration.asHours()
is in decimal. Could you give an example of your expected output?
– Michiel
Mar 8 at 20:01
add a comment |
Thanks but how to covert to decimal?
– Jon Sud
Mar 8 at 19:43
duration.asHours()
is in decimal. Could you give an example of your expected output?
– Michiel
Mar 8 at 20:01
Thanks but how to covert to decimal?
– Jon Sud
Mar 8 at 19:43
Thanks but how to covert to decimal?
– Jon Sud
Mar 8 at 19:43
duration.asHours()
is in decimal. Could you give an example of your expected output?– Michiel
Mar 8 at 20:01
duration.asHours()
is in decimal. Could you give an example of your expected output?– Michiel
Mar 8 at 20:01
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069681%2fhow-to-get-difference-between-times-in-decimal-in-moment-js%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown