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

link|improve this question

75% accept rate
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
feedback

2 Answers

up vote 3 down vote accepted

What about:

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

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)))
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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