Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 2 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
1  
Thanks for your answer! :) –  arcyqwerty Apr 17 '12 at 5:00
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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