I have a complete date plus hours and minutes. I would like to add a number of seconds and display the result as a date "day.month.year hour:minute".
"date" doesn't seem to be able to add seconds to a given date.
I have a complete date plus hours and minutes. I would like to add a number of seconds and display the result as a date "day.month.year hour:minute".
"date" doesn't seem to be able to add seconds to a given date.
In fact, the GNU
date
command (which is the standard implementation in Ubuntu) can add date offsets directly - for example to add 3662 seconds (1hr, 1min, 2sec) to a given dateHowever, some care is required with timezones and daylight savings - a safer option is probably to convert the original time into seconds since the start of the epoch, and add the desired offset to that before converting back to the desired format, e.g.
You can also increment the current date easily with:
man date
says this is documented ininfo date
, but I don't feel like readinginfo
manuals now to quote it :-)Tested in Ubuntu 18.04,
date
from Coreutils 8.28.Like this:
It shows a US styled data for me but see man date for more refinement. The 2 interesting options:
And if you want to use the standard year, month, day format: