Stack Exchange network consists of 178 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
How do I find the number of seconds till midnight of current day?
echo $(($(date -d "$(date +00:00-24:00)" +%s)-$(date +%s)))
If you have a version of date that supports it:
echo $(($(date -d 23:59:59 +%s) - $(date +%s) + 1))
echo $(($(date -d 'tomorrow 00:00:00' +%s) - $(date +%s)))
If you want a solution which works always try this:
$((`date +%s` % 86400 + $OFFSET ))
The $OFFSET should be the difference in seconds between the local timezone and UTC.
Required, but never shown