I have a Webhook listener that receives a unix timestamp value. This timestamp is my END time.
I would like to use the current unix timestamp and compare what HH:MM:SS are left until the end time.
I was reading this post: How can i find HH:MM:SS difference between two UNIX timestamps? and think it is very similar to my needs but needs a little tweaking.
Example:
Current time = unix now time
End time = unix time
= How many HH:MM:SS remain before the time has ended
I was trying;
function timeDiff(EpochTime) {
let msec = (new Date()).valueOf() - EpochTime * 1000;
const hh = Math.floor(msec / 1000 / 60 / 60);
msec -= hh * 1000 * 60 * 60;
const mm = Math.floor(msec / 1000 / 60);
msec -= mm * 1000 * 60;
const ss = Math.floor(msec / 1000);
msec -= ss * 1000;
return `${mm}m ${ss}s`;
}
Thanks Magik
GNU awk is an option:
awk -v etim="2021 02 08 16 27 00" '{ print strftime("%c",mktime(etim)-strftime("%s"),1) }' <<< /dev/null
Pass the date/time as etim and the use GNU awk's strftime and mktime functions to print the difference in the passed date and now in the locale format. Change %c to what ever format is required.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.