Debian 9 vs Debian 10 different date output, the same locale, the same timezone

1

Could you please advise what is the reason of this difference? How can I change the output of Debian 10 to display 24 hours format with date command (with no additional parameters).

Debian 9

date output:

Wed Oct 30 13:10:21 CET 2019

timedatectl:

      Local time: Wed 2019-10-30 13:11:46 CET
  Universal time: Wed 2019-10-30 12:11:46 UTC
        RTC time: Wed 2019-10-30 12:11:46
       Time zone: Europe/Warsaw (CET, +0100)
 Network time on: yes
NTP synchronized: yes
 RTC in local TZ: no

locale output:

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

locale -a output:

C
C.UTF-8
en_US.utf8
POSIX

Debian 10

date:

Wed 30 Oct 2019 01:10:57 PM CET

timedatectl:

               Local time: Wed 2019-10-30 13:11:13 CET
           Universal time: Wed 2019-10-30 12:11:13 UTC
                 RTC time: n/a
                Time zone: Europe/Warsaw (CET, +0100)
System clock synchronized: yes
              NTP service: inactive
          RTC in local TZ: no

locale output:

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME=en_US.utf8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

locale -a output:

aa_DJ
aa_DJ.utf8
aa_ER
aa_ER@saaho
aa_ET
af_ZA
af_ZA.utf8
agr_PE
ak_GH
am_ET
an_ES
an_ES.utf8
anp_IN
ar_AE
ar_AE.utf8
ar_BH
ar_BH.utf8
ar_DZ
ar_DZ.utf8
ar_EG
ar_EG.utf8
ar_IN
ar_IQ
ar_IQ.utf8
ar_JO
ar_JO.utf8
ar_KW
ar_KW.utf8
ar_LB
ar_LB.utf8
ar_LY
ar_LY.utf8
ar_MA
ar_MA.utf8
ar_OM
ar_OM.utf8
ar_QA
ar_QA.utf8
ar_SA
ar_SA.utf8
ar_SD
ar_SD.utf8
ar_SS
ar_SY
ar_SY.utf8
ar_TN
ar_TN.utf8
ar_YE
ar_YE.utf8
as_IN
ast_ES
ast_ES.utf8
ayc_PE
az_AZ
az_IR
be_BY
be_BY@latin
be_BY.utf8
bem_ZM
ber_DZ
ber_MA
bg_BG
bg_BG.utf8
bhb_IN.utf8
bho_IN
bho_NP
bi_VU
bn_BD
bn_IN
bo_CN
bo_IN
br_FR
br_FR@euro
br_FR.utf8
brx_IN
bs_BA
bs_BA.utf8
byn_ER
C
ca_AD
ca_AD.utf8
ca_ES
ca_ES@euro
ca_ES.utf8
ca_ES@valencia
ca_FR
ca_FR.utf8
ca_IT
ca_IT.utf8
ce_RU
chr_US
cmn_TW
crh_UA
csb_PL
cs_CZ
cs_CZ.utf8
C.UTF-8
cv_RU
cy_GB
cy_GB.utf8
da_DK
da_DK.utf8
de_AT
de_AT@euro
de_AT.utf8
de_BE
de_BE@euro
de_BE.utf8
de_CH
de_CH.utf8
de_DE
de_DE@euro
de_DE.utf8
de_IT
de_IT.utf8
de_LI.utf8
de_LU
de_LU@euro
de_LU.utf8
doi_IN
dsb_DE
dv_MV
dz_BT
el_CY
el_CY.utf8
el_GR
el_GR@euro
el_GR.utf8
en_AG
en_AU
en_AU.utf8
en_BW
en_BW.utf8
en_CA
en_CA.utf8
en_DK
en_DK.iso885915
en_DK.utf8
en_GB
en_GB.iso885915
en_GB.utf8
en_HK
en_HK.utf8
en_IE
en_IE@euro
en_IE.utf8
en_IL
en_IN
en_NG
en_NZ
en_NZ.utf8
en_PH
en_PH.utf8
en_SC.utf8
en_SG
en_SG.utf8
en_US
en_US.iso885915
en_US.utf8
en_ZA
en_ZA.utf8
en_ZM
en_ZW
en_ZW.utf8
eo
es_AR
es_AR.utf8
es_BO
es_BO.utf8
es_CL
es_CL.utf8
es_CO
es_CO.utf8
es_CR
es_CR.utf8
es_CU
es_DO
es_DO.utf8
es_EC
es_EC.utf8
es_ES
es_ES@euro
es_ES.utf8
es_GT
es_GT.utf8
es_HN
es_HN.utf8
es_MX
es_MX.utf8
es_NI
es_NI.utf8
es_PA
es_PA.utf8
es_PE
es_PE.utf8
es_PR
es_PR.utf8
es_PY
es_PY.utf8
es_SV
es_SV.utf8
es_US
es_US.utf8
es_UY
es_UY.utf8
es_VE
es_VE.utf8
et_EE
et_EE.iso885915
et_EE.utf8
eu_ES
eu_ES@euro
eu_ES.utf8
eu_FR
eu_FR@euro
eu_FR.utf8
fa_IR
ff_SN
fi_FI
fi_FI@euro
fi_FI.utf8
fil_PH
fo_FO
fo_FO.utf8
fr_BE
fr_BE@euro
fr_BE.utf8
fr_CA
fr_CA.utf8
fr_CH
fr_CH.utf8
fr_FR
fr_FR@euro
fr_FR.utf8
fr_LU
fr_LU@euro
fr_LU.utf8
fur_IT
fy_DE
fy_NL
ga_IE
ga_IE@euro
ga_IE.utf8
gd_GB
gd_GB.utf8
gez_ER
gez_ER@abegede
gez_ET
gez_ET@abegede
gl_ES
gl_ES@euro
gl_ES.utf8
gu_IN
gv_GB
gv_GB.utf8
hak_TW
ha_NG
he_IL
he_IL.utf8
hif_FJ
hi_IN
hne_IN
hr_HR
hr_HR.utf8
hsb_DE
hsb_DE.utf8
ht_HT
hu_HU
hu_HU.utf8
hy_AM
hy_AM.armscii8
ia_FR
id_ID
id_ID.utf8
ig_NG
ik_CA
is_IS
is_IS.utf8
it_CH
it_CH.utf8
it_IT
it_IT@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_RS@latin
ss_ZA
st_ZA
st_ZA.utf8
sv_FI
sv_FI@euro
sv_FI.utf8
sv_SE
sv_SE.iso885915
sv_SE.utf8
sw_KE
sw_TZ
szl_PL
ta_IN
ta_LK
tcy_IN.utf8
te_IN
tg_TJ
tg_TJ.utf8
the_NP
th_TH
th_TH.utf8
ti_ER
ti_ET
tig_ER
tk_TM
tl_PH
tl_PH.utf8
tn_ZA
to_TO
tpi_PG
tr_CY
tr_CY.utf8
tr_TR
tr_TR.utf8
ts_ZA
tt_RU
tt_RU@iqtelif
ug_CN
uk_UA
uk_UA.utf8
unm_US
ur_IN
ur_PK
uz_UZ
uz_UZ@cyrillic
uz_UZ.utf8
ve_ZA
vi_VN
wa_BE
wa_BE@euro
wa_BE.utf8
wae_CH
wal_ET
wo_SN
xh_ZA
xh_ZA.utf8
yi_US
yi_US.utf8
yo_NG
yue_HK
yuw_PG
zh_CN
zh_CN.gb18030
zh_CN.gbk
zh_CN.utf8
zh_HK
zh_HK.utf8
zh_SG
zh_SG.gbk
zh_SG.utf8
zh_TW
zh_TW.euctw
zh_TW.utf8
zu_ZA
zu_ZA.utf8

Liam Packton

Posted 2019-10-30T12:16:41.337

Reputation: 13

I'm not sure if this is a right way to that, but I compared "locale" output. – Liam Packton – 2019-10-30T14:28:42.987

Note: there is en_US.UTF-8 and en_US.utf8 in the question, but this answer states it shouldn't matter.

– Kamil Maciorowski – 2019-10-30T23:16:25.273

Answers

1

Could you please advise what is the reason of this difference?

I downloaded appropriate packages (locales) for Debian 9 and Debian 10 and examined the files named en_US. I also followed this guide and managed to inject both files under custom names, so I could set LC_TIME=en_UScustom9.UTF-8 or LC_TIME=en_UScustom10.UTF-8 to use the locale from Debian 9 or 10 respectively with any command on the same system (for the record: the system was Debian 9).

Conclusions:

  1. The file for Debian 10 contains

    % Appropriate date and time representation (%c)
    d_t_fmt "%a %d %b %Y %r %Z"
    

    and

    % Appropriate date and time representation for date(1)
    date_fmt "%a %d %b %Y %r %Z"
    

    But the file for Debian 9 contains

    % Appropriate date and time representation (%c)
    %       "%a %d %b %Y %r %Z"
    d_t_fmt "<U0025><U0061><U0020><U0025><U0064><U0020><U0025><U0062><U0020><U0025><U0059><U0020><U0025><U0072><U0020><U0025><U005A>"
    

    and there is no entry for date_fmt!

  2. In effect this happens:

    $ LC_TIME=en_UScustom10.UTF-8 locale d_t_fmt                                                                               
    %a %d %b %Y %r %Z
    $ LC_TIME=en_UScustom10.UTF-8 locale date_fmt                                                                              
    %a %d %b %Y %r %Z
    $ LC_TIME=en_UScustom9.UTF-8 locale d_t_fmt
    %a %d %b %Y %r %Z
    $ LC_TIME=en_UScustom9.UTF-8 locale date_fmt
    %a %b %e %H:%M:%S %Z %Y
    $
    

    I guess in the last case date_fmt falls back to the default value. Compare:

    $ LC_TIME=POSIX locale date_fmt
    %a %b %e %H:%M:%S %Z %Y
    $
    
  3. I understand d_t_fmt describes %c format, while date_fmt describes the default format for date. This happens:

    $ LC_TIME=en_UScustom10.UTF-8 date +%c
    Thu 31 Oct 2019 01:23:01 AM CET
    $ LC_TIME=en_UScustom10.UTF-8 date
    Thu 31 Oct 2019 01:23:01 AM CET
    $ LC_TIME=en_UScustom9.UTF-8 date +%c
    Thu 31 Oct 2019 01:23:02 AM CET
    $ LC_TIME=en_UScustom9.UTF-8 date
    Thu Oct 31 01:23:02 CET 2019
    $
    
  4. It seems what you observed in Debian 10 is the right behavior for en_US.UTF-8. In Debian 9 date_fmt is not defined, it's probably a bug. I guess date_fmt should match d_t_fmt, the file should be patched.

    If it's patched, it won't help you at all. It will make date in Debian 9 behave like in Debian 10. You want the behavior from Debian 9.


How can I change the output of Debian 10 to display 24 hours format with date command? (with no additional parameters).

Choose one:

  • Create a custom locale (copy the one from Debian 9) with a custom name and use it.
    (I won't cover this topic here. Do research and ask a separate question if needed.)
  • Place this in your .profile:

    export LC_TIME=POSIX
    

    This way sole date will print the format you want. Note this solution will affect other formats (like %c) as well; decide if it's acceptable.

If I were you I would apply the chosen solution not only to Debian 10 but also to Debian 9, in case the file gets patched.

Kamil Maciorowski

Posted 2019-10-30T12:16:41.337

Reputation: 38 429

+1 Just the hack I was looking for, but you could elaborate where those locale definition file you quoted from are located (/usr/share/i18n/locales). That wasn't entirely obvious. – nyov – 2019-11-07T10:50:39.420

0

From the GNU coreutils page:

Invoking date with no format argument is equivalent to invoking it with a default format that depends on the LC_TIME locale category. In the default C locale, this format is ‘'+%a %b %e %H:%M:%S %Z %Y'’, so the output looks like ‘Thu Mar 3 13:47:51 PST 2005’.

So what is the output of locale LC_TIME (and in particular the next-to-last line) on both systems?

Note that the value of the variable LC_TIME may not be a valid locale name on one of the systems, in which case it looks like the default C locale is used.

Workaround

For your command prompt you can define an alias:

alias date='date "+%c"

%c is the locale-sensitive format:

alias date='date +%c'

>export LC_TIME=en_US.utf8
>date
Wed 30 Oct 2019 01:33:24 PM CET

>export LC_TIME=en_GB.utf8
>date
Wed 30 Oct 2019 13:35:09 CET

You can of course define an alias with your own hand-tailored date format.

xenoid

Posted 2019-10-30T12:16:41.337

Reputation: 7 552

Thank you for your comment. I have: LC_TIME="en_US.UTF-8" on both hosts - I don't understand why the output is different. I don't want to create aliases - I would like to understand the difference between Debian 9 and 10. – Liam Packton – 2019-10-30T14:31:25.683

@LiamPackton See edited answer. – xenoid – 2019-10-30T15:09:35.303