How can I manually set date and time to future in EC2 instance and make it permanent, so it won't reset after reboot ?

I can change date using this command:

$ sudo timedatectl set-time "2017-12-09 16:00:00"
$ timedatectl 
      Local time: Sat 2017-12-09 16:00:01 UTC
  Universal time: Sat 2017-12-09 16:00:01 UTC
        RTC time: Sat 2017-12-09 16:00:02
       Time zone: Etc/UTC (UTC, +0000)
 Network time on: no
NTP synchronized: no
 RTC in local TZ: no

OS on EC2:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:    16.04
Codename:   xenial

What else should I do to make this permanent ?

The purpose of this adjustment is to set the date to future, so I can test few things.

  • What OS are you using? Nov 2 '17 at 14:22
  • @Hunter.S.Thompson Updated the question with OS. Nov 2 '17 at 14:39
  • I wrote an answer I feel will meet your needs better than what you asked. Tell me if that doesn't...
    – Zip
    Nov 2 '17 at 17:22

You can setup ntp for your instance.

Install the package ntp

apt-get/yum install ntp

Edit the configuration

nano /etc/ntp.conf

Add an ntp server to the config file, depending on the country you live in find the appropriate server(Just google "your_country_name ntp server"). Depending on your OS, the configuration file might have server instead of pool or vise versa.

server/pool 0.ntp_server_in_your_country iburst

Restart and enable the ntpd daemon.

systemctl enable ntpd && systemctl start ntpd

ntp will make sure you have the correct time every time you restart the server, that is because it synchronizes the time with that of the server.

  • This will sync the time but I need to manually set the time to future and keep it that way, so I can test some things. Nov 2 '17 at 14:37

Libfaketime, if preloaded with your application can add offsets or set specific times as the current time. It may work better than setting a system wide change.

It can also set a system wide time if you need, though.

Basic usage is:

LD_PRELOAD=/usr/local/lib/libfaketime.so.1 FAKETIME="2017-12-09 16:00:00" commandyouneed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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