Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How do I find the number of seconds till midnight of current day?

share|improve this question
    
Doens't that rather belong to stackoverflow? –  Benoit Mar 16 '11 at 15:14
    
@Benoit : I considered that, but decided against because I thought that this would be scripting, not programming. –  bguiz Mar 16 '11 at 23:02
    
Warning: you are trying to do interval arithmetic with absolute times of day. Think carefully about what happens around DST transitions. –  Phil May 18 '11 at 14:00
    
@Phil : Yup, a solution which takes DST (and other corner cases) would be ideal –  bguiz May 23 '11 at 13:02

2 Answers 2

up vote 4 down vote accepted

What about:

echo $(($(date -d "$(date +00:00-24:00)" +%s)-$(date +%s)))
share|improve this answer

If you have a version of date that supports it:

echo $(($(date -d 23:59:59 +%s) - $(date +%s) + 1))

or

echo $(($(date -d 'tomorrow 00:00:00' +%s) - $(date +%s)))
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.