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


I have already seen some questions / answers related to this question for other programming languages ​​or operating system but for me General Solutions Not Found Specific Scenarios I want to get the timezone given to GMT (General Identifier such as ADT, CET or Europe / Berlin) in Linux shell script or pure C

An easy solution would be: $ TZ = ": Europe / Berlin" date +% z

but it Current GMT offset will print (if it is currently in use with DST)

A better example of what I mean:

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

I have always been a non-denial

< Strong> Other questions that can solve my problem and related to:

The correct non-DST timezone (ATC / GMT-1) of a given city (Europe / Berlin) How to find out? O / offset to know in advance w / o?

How do you usually know that DST is active on a given timestamp?

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

Identifier CEST (Central European Summer Time) and CET (Central European Time) Probably not known in other parts, so the option to get something like DST = 1 or DST = 0 would be better if someone needed it, through Zdump, you can use all timestamps For as you can get isdst = 0 or isdst = 1 which DST change, but it is not IMO very easily.

This will return to the non-DST of the current year given time zone given by GMT:

  zdump -v "Europe / Berlin" | \ sed ": a; n; \ $! ba; s /^.*$ (echo -n $ (date +% Y)) [^] * isdst = 0 \ gmtoff = \ ([^ \ n] * \ ) \ n. * $ / \ 1 / "3600   

What's happening here is that the first non-DST line of the current time has returned by zdump to that time zone, and then The GDT offset is offset in seconds, which is the complete zdump output with the end of the first matching line.

If you need it + HHMM or -HHMM formatted in:

  offset array = ($ (zdump -v "America / New_York" | sed ": a; N ^ \ \ $! BA; s /^.*$ (echo-N $ (date +% Y)) [^] * Isdst = 0 \ gmtoff = \ (- * \) \ ([^ \ n] * \ ) $ {offsetArray [0]: 0: 1} $ (date- $ @ $ offset array [1]} +% H% M) "-0500 < / Code>  

This creates an array with two elements, signals and absolute value, it produces an offset off second, and later it's an era (1 January 1900 00: 00 : 00: 00 UTC / GMT) since time through Since the array array assigns ignore the major white space, the first element of the array is actually "+" or "- +", and the one that looks is the first letter (i.e. + or -). On the one hand, I would think that each year should have the same non-DST offset from the GMT listed by zdump, and in my original answer it was found that he gets hold of the first year, but I Theoretical edge floods In the current year to investigate cases where the time zone 1 9 01 or changed after some time.

(You can remove previous backslash to get instructions in a single line, or two lines in the case of another example).

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -