시간대를 어떻게 알 수 있나요?

시간대를 어떻게 알 수 있나요?

타임스탬프(평신도의 관점에서)는 로케일 문자열이 추가된 ISO8601 문자열(일반적으로 POSIX 지정 형식의 출력 %FT%T)일 수 있습니다(느슨하게 날짜에서 사용할 수 있는 두 가지 형식 중 하나 또는 %Z) %z.

그러면 타임스탬프 문자열은 특정 "시점"이 됩니다. 즉, 정의되지 않은 현지 시간이 없습니다(최소 24개의 서로 다른 고유 값 포함).

이러한 "특정 시점" 문자열은 +'%s'정보 손실 없이 에포크 값(형식의 결과)으로 변환될 수 있습니다.

예를 들어 입력은 열 1과 2에 있고 출력은 열 3과 4에 있습니다.

$ cat indate
2020-03-02T12:23:34 UTC         1583151814  2020-03-02T06:23:34CST-0600
2020-03-02T12:23:34 Z           1583151814  2020-03-02T06:23:34CST-0600
2020-03-02T12:23:34 EST         1583169814  2020-03-02T11:23:34CST-0600
2020-03-02T12:23:34 CST         1583173414  2020-03-02T12:23:34CST-0600
2020-03-02T12:23:34 AST         1583166214  2020-03-02T10:23:34CST-0600
2020-03-02T12:23:34 ADT         1583162614  2020-03-02T09:23:34CST-0600
2020-03-02T12:23:34 EDT         1583166214  2020-03-02T10:23:34CST-0600
2020-03-02T12:23:34 BST         1583148214  2020-03-02T05:23:34CST-0600
2020-03-02T12:23:34 IST         1583132014  2020-03-02T00:53:34CST-0600
2020-03-02T12:23:34 +00:00      1583151814  2020-03-02T06:23:34CST-0600
2020-03-02T12:23:34 -0400       1583166214  2020-03-02T10:23:34CST-0600
2020-03-02T12:23:34 -0800       1583180614  2020-03-02T14:23:34CST-0600
2020-03-02T12:23:34 +06:00      1583130214  2020-03-02T00:23:34CST-0600

요청의 출력은 시간대 및 (가능한 경우) %Z%z값으로 덮어쓴 타임스탬프를 고려하여 에포크 이후의 초 수여야 합니다.

우리 모두 알고 있듯이 GNU date는 열 1과 2에서 이 모든 것을 자체적으로 처리할 수 있습니다.

$ date -f indate +%s

문제는 awk에 대한 해결책이 있습니까?

내가 그것을 얻을 수 있는 유일한 방법은AWK에서이는 많은 재포맷을 수반하는 GNU Date를 사용하여 수행되며, 각 새 줄에 대해 외부 실행 파일을 호출하고 이를 awk로 반환합니다. 나는 date를 한 번만 호출하는 방법이 있다고 생각하지만 그것은 여전히 ​​외부 실행 파일입니다.

더 좋은 방법이 있나요awk를 사용하세요?

내가 작성한 awk 스크립트는 다음과 같습니다.

$ cat tst.awk
#!/bin/bash
awk 'BEGIN{FS="[ \t:T-]*"}
     {

        cmd="date -d '\''"$1 $2"'\'' +'\''%s'\''";
        while ( ( cmd | getline fmtDate) > 0 ) {
            val = fmtDate
        }
        close(cmd);

        datestr=$1" "$2" "$3" "$4" "$5" "$6" 0 "
        print mktime(datestr),$1,$2,"\t",cmd,"\t",val

    }'  indate

그리고 출력은 올바른 것 같습니다(현지 EST 시간 기준).

$ ./tst.awk
1607012614 2020-12-03T12:23:34 UTC  date -d '2020-12-03T12:23:34 UTC' +'%s' 1606998214
1607012614 2020-12-03T12:23:34 Z    date -d '2020-12-03T12:23:34 Z' +'%s'   1606998214
1607012614 2020-12-03T12:23:34 EST  date -d '2020-12-03T12:23:34 EST' +'%s' 1607016214
1607012614 2020-12-03T12:23:34 EDT  date -d '2020-12-03T12:23:34 EDT' +'%s' 1607012614
1607012614 2020-12-03T12:23:34 BST  date -d '2020-12-03T12:23:34 BST' +'%s' 1606994614
1607012614 2020-12-03T12:23:34 IST  date -d '2020-12-03T12:23:34 IST' +'%s' 1606978414
1607012614 2020-12-03T12:23:34 +00:00   date -d '2020-12-03T12:23:34 +00:00' +'%s'  1606998214
1607012614 2020-12-03T12:23:34 -0400    date -d '2020-12-03T12:23:34 -0400' +'%s'   1607012614
1607012614 2020-12-03T12:23:34 -0800    date -d '2020-12-03T12:23:34 -0800' +'%s'   1607027014
1607012614 2020-12-03T12:23:34 +06:00   date -d '2020-12-03T12:23:34 +06:00' +'%s'  1606976614

답변1

다음은 사용자 환경의 시간대를 이해하지만 데이터에서 직접적으로는 이해하지 못하는 GNU awk의 다양한 확장에 대한 모든 것입니다.

정확히 원하는 출력은 아닙니다. (모든 TZ 값, 특히 EDT, BST 및 IST가 이식 가능한지, 아니면 awk처럼 TZ 형식으로 추가 처리가 필요한지 모르겠습니다. 추가 조사가 필요합니다.) 하지만 아래에서 TZ를 사용하여 Epoch 출력 이후의 시간(초)에 영향을 미치고 있음을 볼 수 있습니다.

$ gawk '{
    dt = gensub(/\s+\S+$/,"",1); gsub(/[-:T]/," ",dt)
    tz = $NF
    if ( match(tz,/^([-+]?)([0-9]{2}):?([0-9]{2})$/,a) ) {
        tz = (a[1] == "-" ? "+" : "-") a[2] ":" a[3]
    }
    ENVIRON["TZ"] = tz

    epochSecs = mktime(dt)

    ENVIRON["TZ"] = "UTC"
    printf "%-30s ->  %10s  ->  %s UTC\n", $0, epochSecs, strftime("%F %T",epochSecs)
}' indate
2020-12-03T12:23:34 UTC        ->  1606998214  ->  2020-12-03 12:23:34 UTC
2020-12-03T12:23:34 Z          ->  1606998214  ->  2020-12-03 12:23:34 UTC
2020-12-03T12:23:34 EST        ->  1607016214  ->  2020-12-03 17:23:34 UTC
2020-12-03T12:23:34 EDT        ->  1606998214  ->  2020-12-03 12:23:34 UTC
2020-12-03T12:23:34 BST        ->  1606998214  ->  2020-12-03 12:23:34 UTC
2020-12-03T12:23:34 IST        ->  1606998214  ->  2020-12-03 12:23:34 UTC
2020-12-03T12:23:34 +00:00     ->  1606998214  ->  2020-12-03 12:23:34 UTC
2020-12-03T12:23:34 -0400      ->  1607012614  ->  2020-12-03 16:23:34 UTC
2020-12-03T12:23:34 -0800      ->  1607027014  ->  2020-12-03 20:23:34 UTC
2020-12-03T12:23:34 +06:00     ->  1606976614  ->  2020-12-03 06:23:34 UTC

위의 내용은 환경 변수 값을 사용하고 GNU가 필요한 스크립트에서 실행 중인 awk 스크립트의 환경에서 값을 변경할 수 있는 것에 의존합니다 mktime()( 타임스탬프를 쉽게 비교하기 위해 파생된 에포크 초에서 UTC 시간을 출력하기 위한 것임). awk 버전 4.2 이상 내부.strftime()TZTZ

예를 들어 입력 끝에 숫자가 있는 날짜의 경우 2020-12-03T12:23:34 +06:00날짜는 +06:00시간대로 사용되지 않고 UTC로 제공된 타임스탬프에 적용되는 사람이 읽을 수 있는 증분으로 사용됩니다. date -d '2020-12-03T12:23:34 +06:00' +'%s'(whichoutputs 1606976614.which는 2020-12-03T12:23:34 UTC- 6시간)과 TZ='+06:00' date -d '2020-12-03T12:23:34' +'%s'(whichoutputs 1607019814.which는 2020-12-03T12:23:34 UTC+ 6시간) 을 사용하면 차이를 확인할 수 있습니다.

따라서 위의 기호를 실제 시간대로 처리하는 대신 UTC로 처리한 후 타임스탬프에 적용된 증분으로 처리하는 것과 동일한 방식으로 처리되도록 tz바꿔야 합니다 .date

흥미롭게도 date시간대가 타임스탬프 문자열의 일부로 제공되지 않고 TZ로 설정되면 EDT, BST 및 IST 시간대 처리 측면에서 gawk와 동일하게 동작하지만 :a에 대한 값이 없으면 당연히 실패합니다. TZ로 설정된 경우 중앙에 위치:

$ while read -r ts tz; do
    printf '%s:\t %s  vs  %s\n' "$tz" "$(date +'%s' -d"$ts $tz")" $(TZ="$tz" date '+%s' -d"$ts")
done < indate
UTC:     1606998214  vs  1606998214
Z:   1606998214  vs  1606998214
EST:     1607016214  vs  1607016214
EDT:     1607012614  vs  1606998214
BST:     1606994614  vs  1606998214
IST:     1606978414  vs  1606998214
+00:00:  1606998214  vs  1606998214
-0400:   1607012614  vs  1606998214
-0800:   1607027014  vs  1606998214
+06:00:  1606976614  vs  1607019814

date -d따라서 시간대를 읽는 것 외에 몇 가지 마법이 관련된 것 같습니다.매뉴얼 페이지as mostly free format human readable date string및 와 같은 문자열을 포함할 수 있습니다 next Thursday.

물론, 데이터에 사용된 이식 불가능한 TZ 값을 이식 가능한 값으로 매핑하기 위해 이와 같은 awk 스크립트를 작성할 수도 있습니다(참조https://vdc-repo.vmware.com/vmwb-repository/dcr-public/790263bc-bd30-48f1-af12-ed36055d718b/e5f17bfc-ecba-40bf-a04f-376bbb11e811/timezone.html그리고https://en.wikipedia.org/wiki/List_of_tz_database_time_zones):

$ gawk 'BEGIN {
    tzmap["EST"] = "US/Eastern"
    tzmap["EDT"] = "-04:00"
    tzmap["BST"] = "+01:00"
    tzmap["IST"] = "Asia/Calcutta"
}
{
    dt = gensub(/\s+\S+$/,"",1); gsub(/[-:T]/," ",dt)
    tz = ( $NF in tzmap ? tzmap[$NF] : $NF )
    if ( match(tz,/^([-+]?)([0-9]{2}):?([0-9]{2})$/,a) ) {
        tz = (a[1] == "-" ? "+" : "-") a[2] ":" a[3]
    }
    ENVIRON["TZ"] = tz

    epochSecs = mktime(dt)

    ENVIRON["TZ"] = "UTC"
    printf "%-30s ->  %10s  ->  %s UTC\n", $0, epochSecs, strftime("%F %T",epochSecs)
}' indate
2020-12-03T12:23:34 UTC        ->  1606998214  ->  2020-12-03 12:23:34 UTC
2020-12-03T12:23:34 Z          ->  1606998214  ->  2020-12-03 12:23:34 UTC
2020-12-03T12:23:34 EST        ->  1607016214  ->  2020-12-03 17:23:34 UTC
2020-12-03T12:23:34 EDT        ->  1607012614  ->  2020-12-03 16:23:34 UTC
2020-12-03T12:23:34 BST        ->  1606994614  ->  2020-12-03 11:23:34 UTC
2020-12-03T12:23:34 IST        ->  1606978414  ->  2020-12-03 06:53:34 UTC
2020-12-03T12:23:34 +00:00     ->  1606998214  ->  2020-12-03 12:23:34 UTC
2020-12-03T12:23:34 -0400      ->  1607012614  ->  2020-12-03 16:23:34 UTC
2020-12-03T12:23:34 -0800      ->  1607027014  ->  2020-12-03 20:23:34 UTC
2020-12-03T12:23:34 +06:00     ->  1606976614  ->  2020-12-03 06:23:34 UTC

입력 파일에 어떤 TZ가 나타날 수 있는지 미리 알아야 하는데, 이는 귀하에게 해당되는 것 같습니다.

참고: 위 명령은 Mac에서 실행됩니다. cygwin에서 동일한 명령을 실행하면 TZ값이 이해되지 않습니다. 나는 이것이 다른 종류의 이식성 문제라기보다는 cygwin 문제라고 생각합니다.dateawk

모두와 의논한 끝에시간대 데이터베이스Paul Eggert가 기고했으며, bash와 POSIX 도구를 사용하여 시간대 약어에서 오프셋 및 데이터베이스 이름까지의 매핑 파일을 생성하는 쉘 스크립트를 작성했습니다(시간대 데이터베이스 디렉터리 구조와 올바른 도구 버전이 있는 경우) zdump.

$ cat maptzabbrs
#!/usr/bin/env bash

usage() {
    cat <<'!'
Usage:  maptzabbrs [overrides]
        maptzabbrs --help

Given a timezone database directory like /usr/share/zoneinfo/posix and
a version of zdump (https://man7.org/linux/man-pages/man8/zdump.8.html)
that supports "-i", this will output a tab-separated table of
Abbreviation -> Offset -> Database Names where the list of Database Names
associated with each Abbreviation+Offset will be comma-separated.
Database names without an alphanumeric abbreviation are ignored.

Input: "zdump -i" outputs blank line separated records like:

        TZ="/usr/share/zoneinfo/posix/America/Chicago"
        -       -       -06     CST
        2022-03-13      03      -05     CDT     1
        2022-11-06      01      -06     CST

        TZ="/usr/share/zoneinfo/posix/Asia/Hong_Kong"
        -       -       +08     HKT

Stdout Output (all alphanumeric abbreviations):

        CDT     -04:00  America/Havana,Cuba
        CDT     -05:00  America/Bahia_Banderas,America/Chicago,...
        CST     +08:00  Asia/Chongqing,Asia/Chungking,...
        CST     -05:00  America/Havana,Cuba
        CST     -06:00  America/Bahia_Banderas,...,America/Chicago,...
        HKT     +08:00  Asia/Hong_Kong,Hongkong

Stderr Output (only abbreviations with multiple offsets):

        Warning: abbreviation(s) with multiple alternative offsets:
        CDT     -04:00  America/Havana,Cuba
        CDT     -05:00  America/Bahia_Banderas,America/Chicago,...
        CST     +08:00  Asia/Chongqing,Asia/Chungking,...
        CST     -05:00  America/Havana,Cuba
        CST     -06:00  America/Bahia_Banderas,...,America/Chicago,...

If this tool is called with an argument, that is taken as file of overrides
to disambiguate abbreviations such as the above that would otherwise have
multiple offsets, e.g. if the file "overrides" contained (third column
optional and ignored):

        CDT     -05:00  America/Bahia_Banderas,America/Chicago,...
        CST     -06:00  America/Bahia_Banderas,...,America/Chicago,...

Then calling the tool as

        maptzabbrs overrides

would restrict the stdout for CST and CDT to only be for the stated
offsets and they would not be reported as ambiguous on stderr.

References:
        https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
        https://en.wikipedia.org/wiki/Tz_database

Thanks to the TZ dabatase provider Paul Eggert for background
information and suggestions on how to make this work.
!
}

if [[ "$1" == "--help" ]]; then
    usage
    exit
fi

: tzDir=${tzDir:='/usr/share/zoneinfo/posix'}
(( $# > 0 )) && overrides=$1 || overrides='/dev/null'

ofs='\t'
printf "Zone${ofs}Offset${ofs}Names\n"

find "$tzDir" -type f | sort | xargs zdump -c 2022,2023 -i |
awk -v tzDir="$tzDir" -v OFS="$ofs" '
    FILENAME == ARGV[1] {
        abbr2offset[$1] = $2
        next
    }
    NF {
        if ( sub(/^TZ="/,"") ) {
            sub(/".*/,"")
            name = substr($0,length(tzDir)+2)
        }
        else {
            # change [[:alpha:]] to [[a-zA-Z]] if not supported
            abbr = ($4 ~ /[[:alpha:]]/ ? $4 : "")
            offset = sprintf("%s:%02d",substr($3,1,3),substr($3,4))

            if ( abbr != "" ) {
                abbrs[abbr]
                if ( !(abbr in abbr2offset) ||
                     ((abbr in abbr2offset) && (abbr2offset[abbr] == offset)) ) {
                    if ( !seen_offset[abbr,offset]++ ) {
                        abbrsOffsets[abbr,++numOffsets[abbr]] = offset
                    }
                    if ( !seen_name[abbr,offset,name]++ ) {
                        abbrsNames[abbr,offset,++numNames[abbr,offset]] = name
                    }
                }
            }
        }
    }
    END {
        for ( abbr in abbrs ) {
            for ( offsetNr=1; offsetNr<=numOffsets[abbr]; offsetNr++ ) {
                offset = abbrsOffsets[abbr,offsetNr]
                for ( nameNr=1; nameNr<=numNames[abbr,offset]; nameNr++ ) {
                    name = abbrsNames[abbr,offset,nameNr]
                    names = (nameNr>1 ? names "," : "") name
                }
                print abbr, offset, names | "sort"

                if ( numOffsets[abbr] > 1 ) {
                    gotAmbiguous = 1
                    ambiguous[abbr OFS offset] = names
                }
            }
        }
        close("sort")

        if ( gotAmbiguous ) {
            print "Warning: abbreviation(s) with multiple alternative offsets:" | "cat>&2"
            close("cat>&2")
            for ( abbrOffset in ambiguous ) {
                print abbrOffset, ambiguous[abbrOffset] | "sort>&2"
            }
            close("sort>&2")
        }
    }
' "$overrides" -

이 오버레이 파일이 주어지면 위 코드를 실행하는 데 약 0.5초가 걸립니다.

$ cat overrides
CDT     -05:00  America/Bahia_Banderas,America/Chicago,America/Indiana/Knox,America/Indiana/Tell_City,America/Knox_IN,America/Matamoros,America/Menominee,America/Merida,America/Mexico_City,America/Monterrey,America/North_Dakota/Beulah,America/North_Dakota/Center,America/North_Dakota/New_Salem,America/Rainy_River,America/Rankin_Inlet,America/Resolute,America/Winnipeg,CST6CDT,Canada/Central,Mexico/General,US/Central,US/Indiana-Starke
CST     -06:00  America/Bahia_Banderas,America/Belize,America/Chicago,America/Costa_Rica,America/El_Salvador,America/Guatemala,America/Indiana/Knox,America/Indiana/Tell_City,America/Knox_IN,America/Managua,America/Matamoros,America/Menominee,America/Merida,America/Mexico_City,America/Monterrey,America/North_Dakota/Beulah,America/North_Dakota/Center,America/North_Dakota/New_Salem,America/Rainy_River,America/Rankin_Inlet,America/Regina,America/Resolute,America/Swift_Current,America/Tegucigalpa,America/Winnipeg,CST6CDT,Canada/Central,Canada/Saskatchewan,Mexico/General,US/Central,US/Indiana-Starke
IST     +05:30  Asia/Calcutta,Asia/Kolkata
PST     -08:00  America/Ensenada,America/Los_Angeles,America/Santa_Isabel,America/Tijuana,America/Vancouver,Canada/Pacific,Mexico/BajaNorte,PST8PDT,US/Pacific

내 컴퓨터에서는 다음과 같은 출력이 생성됩니다.

$ /maptzabbrs overrides
Zone    Offset  Names
ACDT    +10:30  Australia/Adelaide,Australia/Broken_Hill,Australia/South,Australia/Yancowinna
ACST    +09:30  Australia/Adelaide,Australia/Broken_Hill,Australia/Darwin,Australia/North,Australia/South,Australia/Yancowinna
ADT     -03:00  America/Glace_Bay,America/Goose_Bay,America/Halifax,America/Moncton,America/Thule,Atlantic/Bermuda,Canada/Atlantic
AEDT    +11:00  Antarctica/Macquarie,Australia/ACT,Australia/Canberra,Australia/Currie,Australia/Hobart,Australia/Melbourne,Australia/NSW,Australia/Sydney,Australia/Tasmania,Australia/Victoria
AEST    +10:00  Antarctica/Macquarie,Australia/ACT,Australia/Brisbane,Australia/Canberra,Australia/Currie,Australia/Hobart,Australia/Lindeman,Australia/Melbourne,Australia/NSW,Australia/Queensland,Australia/Sydney,Australia/Tasmania,Australia/Victoria
AKDT    -08:00  America/Anchorage,America/Juneau,America/Metlakatla,America/Nome,America/Sitka,America/Yakutat,US/Alaska
AKST    -09:00  America/Anchorage,America/Juneau,America/Metlakatla,America/Nome,America/Sitka,America/Yakutat,US/Alaska
AST     -04:00  America/Anguilla,America/Antigua,America/Aruba,America/Barbados,America/Blanc-Sablon,America/Curacao,America/Dominica,America/Glace_Bay,America/Goose_Bay,America/Grenada,America/Guadeloupe,America/Halifax,America/Kralendijk,America/Lower_Princes,America/Marigot,America/Martinique,America/Moncton,America/Montserrat,America/Port_of_Spain,America/Puerto_Rico,America/Santo_Domingo,America/St_Barthelemy,America/St_Kitts,America/St_Lucia,America/St_Thomas,America/St_Vincent,America/Thule,America/Tortola,America/Virgin,Atlantic/Bermuda,Canada/Atlantic
AWST    +08:00  Australia/Perth,Australia/West
BST     +01:00  Europe/Belfast,Europe/Guernsey,Europe/Isle_of_Man,Europe/Jersey,Europe/London,GB,GB-Eire
CAT     +02:00  Africa/Blantyre,Africa/Bujumbura,Africa/Gaborone,Africa/Harare,Africa/Juba,Africa/Khartoum,Africa/Kigali,Africa/Lubumbashi,Africa/Lusaka,Africa/Maputo,Africa/Windhoek
CDT     -05:00  America/Bahia_Banderas,America/Chicago,America/Indiana/Knox,America/Indiana/Tell_City,America/Knox_IN,America/Matamoros,America/Menominee,America/Merida,America/Mexico_City,America/Monterrey,America/North_Dakota/Beulah,America/North_Dakota/Center,America/North_Dakota/New_Salem,America/Rainy_River,America/Rankin_Inlet,America/Resolute,America/Winnipeg,CST6CDT,Canada/Central,Mexico/General,US/Central,US/Indiana-Starke
CEST    +02:00  Africa/Ceuta,Arctic/Longyearbyen,CET,Europe/Amsterdam,Europe/Andorra,Europe/Belgrade,Europe/Berlin,Europe/Bratislava,Europe/Brussels,Europe/Budapest,Europe/Busingen,Europe/Copenhagen,Europe/Gibraltar,Europe/Ljubljana,Europe/Luxembourg,Europe/Madrid,Europe/Malta,Europe/Monaco,Europe/Oslo,Europe/Paris,Europe/Podgorica,Europe/Prague,Europe/Rome,Europe/San_Marino,Europe/Sarajevo,Europe/Skopje,Europe/Stockholm,Europe/Tirane,Europe/Vaduz,Europe/Vatican,Europe/Vienna,Europe/Warsaw,Europe/Zagreb,Europe/Zurich,Poland
CET     +01:00  Africa/Algiers,Africa/Ceuta,Africa/Tunis,Arctic/Longyearbyen,CET,Europe/Amsterdam,Europe/Andorra,Europe/Belgrade,Europe/Berlin,Europe/Bratislava,Europe/Brussels,Europe/Budapest,Europe/Busingen,Europe/Copenhagen,Europe/Gibraltar,Europe/Ljubljana,Europe/Luxembourg,Europe/Madrid,Europe/Malta,Europe/Monaco,Europe/Oslo,Europe/Paris,Europe/Podgorica,Europe/Prague,Europe/Rome,Europe/San_Marino,Europe/Sarajevo,Europe/Skopje,Europe/Stockholm,Europe/Tirane,Europe/Vaduz,Europe/Vatican,Europe/Vienna,Europe/Warsaw,Europe/Zagreb,Europe/Zurich,Poland
CST     -06:00  America/Bahia_Banderas,America/Belize,America/Chicago,America/Costa_Rica,America/El_Salvador,America/Guatemala,America/Indiana/Knox,America/Indiana/Tell_City,America/Knox_IN,America/Managua,America/Matamoros,America/Menominee,America/Merida,America/Mexico_City,America/Monterrey,America/North_Dakota/Beulah,America/North_Dakota/Center,America/North_Dakota/New_Salem,America/Rainy_River,America/Rankin_Inlet,America/Regina,America/Resolute,America/Swift_Current,America/Tegucigalpa,America/Winnipeg,CST6CDT,Canada/Central,Canada/Saskatchewan,Mexico/General,US/Central,US/Indiana-Starke
ChST    +10:00  Pacific/Guam,Pacific/Saipan
EAT     +03:00  Africa/Addis_Ababa,Africa/Asmara,Africa/Asmera,Africa/Dar_es_Salaam,Africa/Djibouti,Africa/Kampala,Africa/Mogadishu,Africa/Nairobi,Indian/Antananarivo,Indian/Comoro,Indian/Mayotte
EDT     -04:00  America/Detroit,America/Fort_Wayne,America/Grand_Turk,America/Indiana/Indianapolis,America/Indiana/Marengo,America/Indiana/Petersburg,America/Indiana/Vevay,America/Indiana/Vincennes,America/Indiana/Winamac,America/Indianapolis,America/Iqaluit,America/Kentucky/Louisville,America/Kentucky/Monticello,America/Louisville,America/Montreal,America/Nassau,America/New_York,America/Nipigon,America/Pangnirtung,America/Port-au-Prince,America/Thunder_Bay,America/Toronto,Canada/Eastern,EST5EDT,US/East-Indiana,US/Eastern,US/Michigan
EEST    +03:00  Asia/Amman,Asia/Beirut,Asia/Damascus,Asia/Famagusta,Asia/Gaza,Asia/Hebron,Asia/Nicosia,EET,Europe/Athens,Europe/Bucharest,Europe/Chisinau,Europe/Helsinki,Europe/Kiev,Europe/Mariehamn,Europe/Nicosia,Europe/Riga,Europe/Sofia,Europe/Tallinn,Europe/Uzhgorod,Europe/Vilnius,Europe/Zaporozhye
EET     +02:00  Africa/Cairo,Africa/Tripoli,Asia/Amman,Asia/Beirut,Asia/Damascus,Asia/Famagusta,Asia/Gaza,Asia/Hebron,Asia/Nicosia,EET,Egypt,Europe/Athens,Europe/Bucharest,Europe/Chisinau,Europe/Helsinki,Europe/Kaliningrad,Europe/Kiev,Europe/Mariehamn,Europe/Nicosia,Europe/Riga,Europe/Sofia,Europe/Tallinn,Europe/Uzhgorod,Europe/Vilnius,Europe/Zaporozhye,Libya
EST     -05:00  America/Atikokan,America/Cancun,America/Cayman,America/Coral_Harbour,America/Detroit,America/Fort_Wayne,America/Grand_Turk,America/Indiana/Indianapolis,America/Indiana/Marengo,America/Indiana/Petersburg,America/Indiana/Vevay,America/Indiana/Vincennes,America/Indiana/Winamac,America/Indianapolis,America/Iqaluit,America/Jamaica,America/Kentucky/Louisville,America/Kentucky/Monticello,America/Louisville,America/Montreal,America/Nassau,America/New_York,America/Nipigon,America/Panama,America/Pangnirtung,America/Port-au-Prince,America/Thunder_Bay,America/Toronto,Canada/Eastern,EST,EST5EDT,Jamaica,US/East-Indiana,US/Eastern,US/Michigan
GMT     +00:00  Africa/Abidjan,Africa/Accra,Africa/Bamako,Africa/Banjul,Africa/Bissau,Africa/Conakry,Africa/Dakar,Africa/Lome,Africa/Monrovia,Africa/Nouakchott,Africa/Ouagadougou,Africa/Sao_Tome,Africa/Timbuktu,America/Danmarkshavn,Atlantic/Reykjavik,Atlantic/St_Helena,Eire,Etc/GMT,Etc/GMT+0,Etc/GMT-0,Etc/GMT0,Etc/Greenwich,Europe/Belfast,Europe/Dublin,Europe/Guernsey,Europe/Isle_of_Man,Europe/Jersey,Europe/London,GB,GB-Eire,GMT,GMT+0,GMT-0,GMT0,Greenwich,Iceland
HDT     -09:00  America/Adak,America/Atka,US/Aleutian
HKT     +08:00  Asia/Hong_Kong,Hongkong
HST     -10:00  America/Adak,America/Atka,HST,Pacific/Honolulu,Pacific/Johnston,US/Aleutian,US/Hawaii
IDT     +03:00  Asia/Jerusalem,Asia/Tel_Aviv,Israel
IST     +05:30  Asia/Calcutta,Asia/Kolkata
JST     +09:00  Asia/Tokyo,Japan
KST     +09:00  Asia/Pyongyang,Asia/Seoul,ROK
MDT     -06:00  America/Boise,America/Cambridge_Bay,America/Chihuahua,America/Denver,America/Edmonton,America/Inuvik,America/Mazatlan,America/Ojinaga,America/Shiprock,America/Yellowknife,Canada/Mountain,MST7MDT,Mexico/BajaSur,Navajo,US/Mountain
MEST    +02:00  MET
MET     +01:00  MET
MSK     +03:00  Europe/Moscow,Europe/Simferopol,Europe/Tiraspol,W-SU
MST     -07:00  America/Boise,America/Cambridge_Bay,America/Chihuahua,America/Creston,America/Dawson,America/Dawson_Creek,America/Denver,America/Edmonton,America/Fort_Nelson,America/Hermosillo,America/Inuvik,America/Mazatlan,America/Ojinaga,America/Phoenix,America/Shiprock,America/Whitehorse,America/Yellowknife,Canada/Mountain,Canada/Yukon,MST,MST7MDT,Mexico/BajaSur,Navajo,US/Arizona,US/Mountain
NDT     -02:30  America/St_Johns,Canada/Newfoundland
NST     -03:30  America/St_Johns,Canada/Newfoundland
NZDT    +13:00  Antarctica/McMurdo,Antarctica/South_Pole,NZ,Pacific/Auckland
NZST    +12:00  Antarctica/McMurdo,Antarctica/South_Pole,NZ,Pacific/Auckland
PDT     -07:00  America/Ensenada,America/Los_Angeles,America/Santa_Isabel,America/Tijuana,America/Vancouver,Canada/Pacific,Mexico/BajaNorte,PST8PDT,US/Pacific
PKT     +05:00  Asia/Karachi
PST     -08:00  America/Ensenada,America/Los_Angeles,America/Santa_Isabel,America/Tijuana,America/Vancouver,Canada/Pacific,Mexico/BajaNorte,PST8PDT,US/Pacific
SAST    +02:00  Africa/Johannesburg,Africa/Maseru,Africa/Mbabane
SST     -11:00  Pacific/Pago_Pago,Pacific/Samoa,US/Samoa
UTC     +00:00  Etc/UCT,Etc/UTC,Etc/Universal,Etc/Zulu,UCT,UTC,Universal,Zulu
WAT     +01:00  Africa/Bangui,Africa/Brazzaville,Africa/Douala,Africa/Kinshasa,Africa/Lagos,Africa/Libreville,Africa/Luanda,Africa/Malabo,Africa/Ndjamena,Africa/Niamey,Africa/Porto-Novo
WEST    +01:00  Atlantic/Canary,Atlantic/Faeroe,Atlantic/Faroe,Atlantic/Madeira,Europe/Lisbon,Portugal,WET
WET     +00:00  Atlantic/Canary,Atlantic/Faeroe,Atlantic/Faroe,Atlantic/Madeira,Europe/Lisbon,Portugal,WET
WIB     +07:00  Asia/Jakarta,Asia/Pontianak
WIT     +09:00  Asia/Jayapura
WITA    +08:00  Asia/Makassar,Asia/Ujung_Pandang

tzmap[]위의 awk 스크립트에서 사용한 배열을 수동으로 채우는 대신 이러한 매핑을 채워야 하는 awk 스크립트에서 도구의 출력을 읽을 수 있습니다 .

답변2

내가 이를 달성할 수 있었던 유일한 방법은 GNU 날짜를 사용하는 것입니다. 여기에는 많은 재포맷이 필요하고, 각 새 줄에 대해 외부 실행 파일을 호출하고 이를 awk로 반환하는 것입니다.

GNU 날짜는 파일에서 날짜를 읽을 수 있습니다.

% cat foo.dates
2020-12-03T12:23:34 UTC
2020-12-03T12:23:34 Z
2020-12-03T12:23:34 EST
2020-12-03T12:23:34 EDT
2020-12-03T12:23:34 BST
2020-12-03T12:23:34 IST
2020-12-03T12:23:34 +00:00
2020-12-03T12:23:34 -0400
2020-12-03T12:23:34 -0800
2020-12-03T12:23:34 +06:00

% date --file foo.dates +%s
1606998214
1606998214
1607016214
1607012614
1606994614
1606978414
1606998214
1607012614
1607027014
1606976614

그렇지 않더라도 이것은 xargsawk의 작업이 아닌 작업인 것 같습니다.

% xargs < foo.dates -n 1 -d '\n' date +%s -d
1606998214
1606998214
1607016214
1607012614
1606994614
1606978414
1606998214
1607012614
1607027014
1606976614

관련 정보