Friday, November 8, 2013

Change date and time the easy way

I recently had the task to simulate some time jumps on the system to test software features which only kick in when I certain amount of time has passed. In my case this was a month. Since I'm a bit lazy and hate to calculate with dates I found this command line to easily change the system date without a lot of thinking

date "+%Y%m%d %H:%M:%S" -s "$(date "+%Y%m%d" -s 'now + 1 month') $(date +%H:%M:%S)"

The argument in the single quotes do the stuff I need to set the current clock to 1 month in the future and keeps the actual time. ( if you change the day alone date sets the time to 00:00)