Discussion:
bug#29589: date %k adds extra space for single digits hours
(too old to reply)
Noam Arad
2017-12-06 09:17:12 UTC
Permalink
When using date command with the format %k if the hour is single digits there is an extra space added.
E.g.: date -u +"%Y/%m/%d %k:%M:%S" when run at "2017/12/06 9:16:26" will give the output "2017/12/06 9:16:26"
NOTE: there are two spaces between "06" and "9".

Thanks
Bishop Bettini
2017-12-06 16:49:07 UTC
Permalink
Post by Noam Arad
When using date command with the format %k if the hour is single digits
there is an extra space added.
E.g.: date -u +"%Y/%m/%d %k:%M:%S" when run at "2017/12/06 9:16:26" will
give the output "2017/12/06 9:16:26"
NOTE: there are two spaces between "06" and "9".
This seems expected. Per the documentation as of GNU coreutils 8.22:

%k hour, space padded ( 0..23); same as %_H

This is just a pass-thru to strftime under the hood, whose documentation
says:

%k The hour (24-hour clock) as a decimal number (range 0 to
23); single digits are preceded by a
blank. (See also %H.) (Calculated from tm_hour.) (TZ)

To format without the space, use %-k:

$ TZ=America/Whitehorse date +'%k'
8
$ TZ=America/Whitehorse date +'%-k'
8
Noam Arad
2017-12-06 18:55:01 UTC
Permalink
Thanks for the quick reply.
Will use your suggestions.

Noam

From: Bishop Bettini [mailto:***@gmail.com]
Sent: Wednesday, December 6, 2017 6:49 PM
To: Noam Arad <***@kaltura.com>
Cc: ***@debbugs.gnu.org
Subject: Re: bug#29589: date %k adds extra space for single digits hours

On Wed, Dec 6, 2017 at 4:17 AM, Noam Arad <***@kaltura.com<mailto:***@kaltura.com>> wrote:
When using date command with the format %k if the hour is single digits there is an extra space added.
E.g.: date -u +"%Y/%m/%d %k:%M:%S" when run at "2017/12/06 9:16:26" will give the output "2017/12/06 9:16:26"
NOTE: there are two spaces between "06" and "9".

This seems expected. Per the documentation as of GNU coreutils 8.22:

%k hour, space padded ( 0..23); same as %_H

This is just a pass-thru to strftime under the hood, whose documentation says:

%k The hour (24-hour clock) as a decimal number (range 0 to 23); single digits are preceded by a
blank. (See also %H.) (Calculated from tm_hour.) (TZ)

To format without the space, use %-k:

$ TZ=America/Whitehorse date +'%k'
8
$ TZ=America/Whitehorse date +'%-k'
Assaf Gordon
2018-10-30 02:16:16 UTC
Permalink
tags 29589 notabug
close 29589
stop

(triaging old bugs)
Post by Noam Arad
When using date command with the format %k if the hour is single digits there is an extra space added.
E.g.: date -u +"%Y/%m/%d %k:%M:%S" when run at "2017/12/06 9:16:26" will give the output "2017/12/06 9:16:26"
NOTE: there are two spaces between "06" and "9".
%k hour, space padded ( 0..23); same as %_H
Thanks for the quick reply. Will use your suggestions.
Given the above, I'm closing this bug.
Discussion can continue by replying to this thread.

-assaf

Continue reading on narkive:
Loading...