Home > Net >  Ubuntu Terminal command: Show what time after X seconds?
Ubuntu Terminal command: Show what time after X seconds?

Time:01-12

I need to know if there is a command where I can show what time it will be after X seconds.

In my case: I often need to set "sleep (seconds)"; in terminal before and between other following commands (seperated by ;) and it would be greatfull to see what time it will be after (seconds).

I know this command: date -d@(seconds) -u %H:%M:%S. But this only show me the duration, so its a conversion. That is a compromise but not exactly what I need.

I hope I explained it understandable and someone can help me^^

Best regards and thanks in advance

CodePudding user response:

You can do a sum to current timestamp (in second) with the coming sleep delay (in seconds too) with $((a b)).

Then, your initial command transforms to:

date -d@$((timestamp   10)) -u  %H:%M:%S

The final command can look like:

date -d@$((`date  %s`   60)) -u  %H:%M:%S

EDIT: As per the OP comment bellow this answer, "Why do I have to add 3600 for not having a timestamp in the past?"

This is due to the local of your system. Indeed, in one part of the command you get the total elapsed seconds from 1970 ... regarding your local, while on the other part, you print the timestamp in reference to UTC.

As your local may be UTC 1 this explains why you have to add one more extra hour (3600 seconds).

You can stick to your system's local with:

date -d@$((`date  %s`   60))  %H:%M:%S
  • Related