Score:1

How to manipulate date keeping the same time via command line

br flag

I am in a need of manipulating the system time for few minutes.

Say I need to keep the time as it is and change the date to next date.
After few minutes.. I need to go back to the normal time with out giving any manual inputs.

How is this possible with command line only.

I have gone through this What is the command line statement for changing the System clock? and it requires to input date+time.

I dont want to change the time, only the date. Once the requirement is done that is after few minutes, I dont want to enter any manual inputs for date and time..

I want to go back to regular time with command line.

BeastOfCaerbannog avatar
ca flag
Does this answer your question? [What is the command line statement for changing the System clock?](https://askubuntu.com/questions/342854/what-is-the-command-line-statement-for-changing-the-system-clock)
Score:3
jp flag

This is an example of what ( I think ) you want. It will change the year only to last year for 4 minutes then back to current date again. Your machine needs to be connected to the Internet for this to work:

sudo bash -c "timedatectl set-ntp off && date -s 'last year' && sleep 4m && timedatectl set-ntp on"
Score:2
ca flag

For the below to work, you should first go to Settings → Date & Time and disable Automatic Date & Time.

You can then use the following command as a (long) one-liner:

sudo date --set="2010-05-02 $(date '+%T')" && sleep 10 && sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"

The above command:

  • Gets the current system time:

    date '+%T'
    

    and sets the date to the one you wish, keeping the current time:

    sudo date --set="2010-05-02 $(date '+%T')"
    

    In this example the date, which you may change to what you need, is 2010-05-02.

  • Keeps the altered date for the specified time interval using the sleep command. Here I have used sleep 10 to keep the altered time for 10 seconds. You can add an m, h, or d suffix to sleep's argument (here 10) to specify the time in minutes, hours, or days, respectively.

  • Reverts the time to the current time (requires internet access):

    sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
    

    Credits to Shrukul Habib.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.