How to know when time zone has changed and when timezone will change in linux

There are timezones where daylight saving time applies due to which timezone changes twice a year which creates problem in few programmes running on the system. I am looking for a way to get when the next timezone change will takes place

Tagged:

Answers

  • sachin
    edited November 2023

    You can use zdump:

    NAME
           zdump - timezone dumper
    
    SYNOPSIS
           zdump [ --version ] [ --help ] [ -v ] [ -c [loyear,]hiyear ] [ zonename ... ]
    
    DESCRIPTION
           Zdump prints the current time in each zonename named on the command line.
    

    Example:

    zdump -v -c 2023,2025 "Europe/Berlin"
    

    You may reffer https://man7.org/linux/man-pages/man8/zdump.8.html

    And to be able to print even in better format, easier to use inside codes and getting the system time zone dynamically, you can use the command (feel free to update as per your requirement).

    zdump -v -c 2023,2025 "$(timedatectl | grep 'Time zone' | awk -F ': ' '{print $2}' | awk -F ' ' '{print $1}')" | grep isdst | awk '{print $9","$10","$11","$12","$13","$14","$15}'
    
  • The above command will give the list of dates when timezone changes, you can also try another command in linux.

    timedatectl status
    

    This will output all the details you need on timezone

          Local time: Wed 2023-11-22 04:26:14 EST
      Universal time: Wed 2023-11-22 09:26:14 UTC
            RTC time: Wed 2023-11-22 09:26:12
           Time zone: America/New_York (EST, -0500)
         NTP enabled: yes
    NTP synchronized: yes
     RTC in local TZ: no
          DST active: no
     Last DST change: DST ended at
                      Sun 2023-11-05 01:59:59 EDT
                      Sun 2023-11-05 01:00:00 EST
     Next DST change: DST begins (the clock jumps one hour forward) at
                      Sun 2024-03-10 01:59:59 EST
                      Sun 2024-03-10 03:00:00 EDT
    
    
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!