Linux get timezone offset

UTC/GMT: Getting the Offset

yields «Time Zone: (UTC-05:00) Eastern Time (US & Canada)» So it would seem as if we are 5 hours behind UTC/GMT. But in Linux I run:

and I get: «-0400» In Linux when I run the date command I get: «Fri Sep 21 15:00:45 EDT 2012» So I’m not sure whether we are 4 or 5 hours behind UTC/GMT. I found this issue because I opened an Atom feed using Firefox and IE. The «updated» date on the feed is «2011-11-09T15:28:23Z», which is the time in UTC. IE displays the local time in the browser as: «11:28:23 AM» while Firefox displays «10:28 AM». Can anyone explain the discrepancy?

2 Answers 2

The difference comes from the fact that Linux date command will include the daylight saving time depending on the time of the year you run the command on, while on Windows it prints the offset without the DST.

Do both Windows and Linux agree on the time? If not, which one agrees with your (non-computer) clock?

Your link says that you live in New York City, which is GMT -5 (the time in Greenwich — 5 hours), and your zone uses Daylight Savings Time (DST) (+1 hour). This put’s you in EDT, or Eastern Daylight Time.

You can set that in Windows 7:

Calendar:

Left-click on the clock in the bottom-right corner of the screen
Click ==> «Change Date and Time Settings. »

(source: mediafire.com)

TimeandDate

Click ==> «Change Time Zone. »

(source: mediafire.com)

Time Zone

==> select «(UTC -5:00) Eastern Time (US & Canada)»
==> Checkmark «Automatically adjust clock for Daylight Savings Time»

(source: mediafire.com)

Click ==> OK ==> OK

Читайте также:  Linux сколько весят папки

Keep in mind that systeminfo will NOT show your DST setting. I know no method of checking or setting that from the command prompt.

I do not know why Firefox and IE would show different times.

Источник

How to Check and Set Timezone in Ubuntu 20.04

In this tutorial, you will learn how to check and set the timezone in Ubuntu 20.04 using the timedatectl command.

There are a variety of ways of checking your timezone, from using the date command to the timedatactl command. However, setting your timezone has been greatly simplified and improved with the timedatactl command.

The timedatectl command allows you to output detailed information about your system’s date in time, from NTP info to comparisons between your date with the UTC date.

While we’ve limited the scope of this tutorial to strictly being about setting your timezone, the timedatectl has additional functionality that is very useful for configurations around time and date.

Checking Your Current Timezone

The currently configured timezone is set in the /etc/timezone file. To view your current timezone you can cat the file’s contents.

Another method is to use the date command. By giving it the argument +%Z , you can output your system’s current time zone name.

To get the timezone name and offset, you can use the data command with the +»%Z %z» argument. The uppercase Z prints the timezone name, while the lowercase z outputs the time offset.

The timedatectl command be used to get more details about your system’s current time and date configurations.

 Local time: Sat 2020-09-05 03:09:26 UTC Universal time: Sat 2020-09-05 03:09:26 UTC RTC time: Sat 2020-09-05 03:09:26 Time zone: Etc/UTC (UTC, +0000) System clock synchronized: yes NTP service: active RTC in local TZ: no 

Setting Your Timezone

To set your timezone the timedatectl command will be used. Before you set your new timezone you may want to know what timezones are available. You can list all available timezones using the timedatectl list-timezones command.

timedatectl list-timezones
Africa/Abidjan Africa/Accra Africa/Algiers Africa/Bissau Africa/Cairo Africa/Casablanca Africa/Ceuta Africa/El_Aaiun Africa/Johannesburg Africa/Juba Africa/Khartoum Africa/Lagos Africa/Maputo Africa/Monrovia Africa/Nairobi Africa/Ndjamena Africa/Sao_Tome . 

The timezone list is very extensive. To narrow the list down to only your region you can pipe the results to the grep command. For example, to narrow our results to only the Americas, we would run the following command.

timedatectl list-timezones | grep America
. America/Santiago America/Santo_Domingo America/Sao_Paulo America/Scoresbysund America/Sitka America/St_Johns America/Swift_Current America/Tegucigalpa America/Thule America/Thunder_Bay America/Tijuana America/Toronto America/Vancouver America/Whitehorse America/Winnipeg America/Yakutat America/Yellowknife

Once you know the time zone you want to set your Ubuntu server to, you use the timedatactl set-timezone command to set it.

sudo timedatectl set-timezone America/Toronto

and then confirm your changes were applied by running the timedatactl command.

 Local time: Fri 2020-09-04 23:30:58 EDT Universal time: Sat 2020-09-05 03:30:58 UTC RTC time: Sat 2020-09-05 03:30:59 Time zone: America/Toronto (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no 

Источник

Читайте также:  Linux kernel image name

GMT/UTC offset in hours/minutes of a given timezone w/o daylight saving time (DST)

I already saw some questions/answers related to this question for other programming languages or operating systems but I found no common solution for my specific scenario. I want to get the GMT offset of a given timezone (normal identifier like EDT, CET or Europe/Berlin) in a Linux shell script or in pure C. One easy solution would be:

But this will print the current GMT offset (including DST if it’s currently in use). Here a better example to show what I mean:

$ TZ=":Europe/Berlin" date +%z --date="1 Jan 2014" +0100 $ TZ=":Europe/Berlin" date +%z --date="1 May 2014" +0200 

I need an option to always get the non-DST value (here: +0100) for any country/city. Other questions that could solve my problem and are related to this one: How to find the correct non-DST timezone (Etc/GMT-1) of a given city (Europe/Berlin) w/o knowing the offset in advance? How do you generally know that DST is active at a given timestamp?

$ TZ=":Europe/Berlin" date --date="2014-01-01" Wed Jan 1 00:00:00 CET 2014 $ TZ=":Europe/Berlin" date --date="2014-05-01" Thu May 1 00:00:00 CEST 2014 

The identifiers CEST (Central European Summer Time) and CET (Central European Time) are maybe not commonly known in other parts of the world, so an option to simply get something like DST=1 or DST=0 would be better if someone needs it. Via zdump you can get isdst=0 or isdst=1 for all timestamps that change DST, but it’s not so easily usable IMO.

Источник

Can I get UTC offset from Unix command line?

I’m writing an autoconf script that needs the current UTC offset. There’s no obvious way to get this out of the date program. Is there any straightforward way to get this from a command-line utility, or should I write a test that gets the information and somehow captures it?

Читайте также:  Чем лучше arch linux

because I want to embed compile time in the program, and TIME doesn’t return the UTC offset, so I can’t turn it into ISO 8601.

3 Answers 3

Try this, and see whether it works for you:

For others doing ISO8601, you might pick some variant of:

date +%Y%m%dT%H%M%S%z # 20140809T092143-0700 date -u +%Y%m%dT%H%M%S%z # 20140809T162143+0000 date -u +%Y%m%dT%H%M%SZ # 20140809T162143Z 

I like those because the lack of punctuation supports universal use. Note that the capital Z is ‘hard-coded’ for UTC — using %Z will put UTC or the other named timezone. If you prefer punctuation:

date +%Y-%m-%dT%H:%M:%S%z # 2014-08-09T09:21:43-0700 date +%Y-%m-%dT%H:%M:%S%:z # 2014-08-09T09:21:43-07:00 - NOT ALL SYSTEMS date -u +%Y-%m-%dT%H:%M:%S%z # 2014-08-09T16:21:43+0000 date -u +%Y-%m-%dT%H:%M:%S%:z # 2014-08-09T16:21:43+00:00 - NOT ALL SYSTEMS date -u +%Y-%m-%dT%H:%M:%SZ # 2014-08-09T16:21:43Z 

Consult man strftime as supported formats vary. For instance, some systems support inserting colons into the offset using %:z, %::z, or %. z — only two of my five systems do (Debian, Ubuntu do, but Mac, BusyBox, QNX do not).

Источник

Оцените статью
Adblock
detector