Need help with date functionality.
Jun 30, 2020
05:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Jun 30, 2020
05:21 AM
Need help with date functionality.
Hi All,
I have 1 date time variables as below.
var Date1 = 2020-06-03 18:02:13.700 //last connection property of a thing in date time datatype
How can I get the difference between current time and Date1 in format of days,hours,minutes, seconds (2 days, 7 hours, 8 minutes, 39 seconds)
Thanks and Regards,
Bhanu.
Solved! Go to Solution.
Labels:
- Labels:
-
Coding
-
Solution Central
ACCEPTED SOLUTION
Accepted Solutions
Jun 30, 2020
05:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Jun 30, 2020
05:55 AM
Something like this may help:
function humanReadableMilliseconds(milliseconds) {
var seconds=~~((milliseconds/1000)%60);
var minutes=~~((milliseconds/(1000*60))%60);
var hours=~~((milliseconds/(1000*60*60))%24);
var days=~~((milliseconds/(1000*60*60*24))%365);
var years=~~((milliseconds/(1000*60*60*24*365))%1000);
return (years?years+'y ':'')+(days?days+'d ':'')+(hours?hours+'h ':'')+(minutes?minutes+'m ':'')+(seconds?seconds+'s ':'');
}
- Tags:
- O
2 REPLIES 2
Jun 30, 2020
05:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Jun 30, 2020
05:55 AM
Something like this may help:
function humanReadableMilliseconds(milliseconds) {
var seconds=~~((milliseconds/1000)%60);
var minutes=~~((milliseconds/(1000*60))%60);
var hours=~~((milliseconds/(1000*60*60))%24);
var days=~~((milliseconds/(1000*60*60*24))%365);
var years=~~((milliseconds/(1000*60*60*24*365))%1000);
return (years?years+'y ':'')+(days?days+'d ':'')+(hours?hours+'h ':'')+(minutes?minutes+'m ':'')+(seconds?seconds+'s ':'');
}
- Tags:
- O
Jun 30, 2020
12:38 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Jun 30, 2020
12:38 PM
Thanks a lot Carles
