Change special hh mm to another time zone

I want to change 0710 (07 hour 10 minute in GMT +0)
to 0810 (08 hour 10 minute in GMT +1)

what command in linux can do it?

Thank you for your support !

Asked By: dvthanh

||

You can usetimedatectl by doint these:

  1. Open a terminal window.

  2. Use the timedatectl list-timezones command to list available time zones. Search for the zone that corresponds to GMT+1. For example:

    timedatectl list-timezones | grep GMT+1
    
  3. Once you’ve identified the GMT+1 timezone (for instance, Europe/Paris is GMT+1), use the timedatectl set-timezone command followed by the identified timezone:

    sudo timedatectl set-timezone Europe/Paris
    

    Replace Europe/Paris with the timezone you found in step 2.

  4. After executing the command, check if the timezone has been updated by using:

    timedatectl
    

    This will display the current system time and date settings, including the new timezone you’ve set.

Remember, using sudo may prompt you for your password to run the command with administrative privileges.

Answered By: SomannaK

If you simply want to add an hour to a four digit time value you can treat is as a standard base 10 number and simply add 100 modulo 2400.

Actually, it gets a bit more complicated than that because we first have to remove any leading zeros so that the shell doesn’t treat the value as octal, and then we need to rebuild the result back to four digits:

a=0710
b=$( printf "%04d" $(( (${a##0}+100) % 2400 )) )
echo b=$b    # "0810"

On the other hand if you want to perform real date/time arithmetic that may vary depending on timezone (and date) you need to be more precise in your requirement.

Answered By: Chris Davies
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.