score:1

using bsd date, you can use the -v to adjust the time properly.

% date
tue may 22 09:21:50 edt 2018
% date  -v 23h -v 59m -v 59s
tue may 22 23:59:59 edt 2018

slightly longer, but saving you from having to remember how many hours are in a day, minutes in an hour, etc, by going to midnight tomorrow, then subtracting one second.

% date -v +1d -v 0h -v 0m -v -0s -v -1s
          ^      ^     ^      ^     ^
          |      |     |      |     |
          |      +-----+------+     subtract one second
          |            |
          |        reset to midnight
          |
          go to tomorrow

(it's a shame -v can't take a combination. date -v+1d0h0ms-1s would be nice to type. it's not terribly readable or obvious, but easy to parse if you know how -v works. whitespace would make it better: date -v "+1d 0h 0m 0s -1s". #wishfulthinking)


a simple but fragile approach is to just round up to the nearest multiple of 86400:

$ now=$(date +%s)
$ end_of_day=$(( now - now%86400 + 86399))

but this won't take daylight savings into account for the two days where it may be relevant.

score:5

you can simply specify that with the -d argument.

i.e. date -d "today 23:59:59" +%s where today 23:29:59 is used to get the end of the current day

edit : @toby propose the following approach to handle correctly leap seconds -d 'tomorrow 0 -1second

if you want the beginning of the day use

date -d "today 0" +%s

Related Query

More Query from same tag