Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using something similar to the date command, is it possible to set the date and time relative to 'now'?

So instead of something like date +%T -s "10:13:13" something like date -s +1h or something similar

share|improve this question
up vote 3 down vote accepted

To set the date, you must log in as root (or su/sudo...)

echo "Time 1 hour ago ... $(date -d "$(date +%F\ %T) 1 hour ago")"
echo "Time now .......... $(date  +%F\ %T)"
echo "Time in 1 hour .... $(date -d "$(date +%F\ %T) 1 hour")"

sudo date +%F\ %T -s "$(date -d "$(date +%F\ %T) 1 hour")"
echo "Adjusted time ..... $(date  +%F\ %T)"

sudo date +%F\ %T -s "$(date -d "$(date +%F\ %T) 1 hour ago")"
echo "Re-adjusted time .. $(date  +%F\ %T)"

output:

Time 1 hour ago ... 2012-04-16 21:31:53
Time now .......... 2012-04-16 22:31:53
Time in 1 hour .... 2012-04-16 23:31:53
[sudo] password for .... 
Adjusted time ..... 2012-04-16 23:31:53
[sudo] password for  .... 
Re-adjusted time .. 2012-04-16 22:31:53
share|improve this answer

You can change your time zone by doing # dpkg-reconfigure tzdata. I'm not sure how you would change the time by an arbitrary value, though.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .