help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: printf %()T


From: Roger
Subject: Re: printf %()T
Date: Tue, 2 May 2023 00:31:14 -0400

On 4/28/23, Greg Wooledge <greg@wooledge.org> wrote:
> On Thu, Apr 27, 2023 at 11:51:25PM -0400, Lee wrote:
>> semi-working:
>>
>> $ printf  "%(%A)T  %(%c)T" 1
>> Wednesday  Thu 27 Apr 2023 11:48:12 PM EDT
>>
>> There's clearly a problem with the day of the week :(
>
> First: you're only passing one argument, but you've got two separate
> %()T specifiers.  So, the first one gets the argument "1", and the second
> one gets the argument "" (which in current versions of bash acts like -1).
>
> Second: the argument "1" means "1 second after the Epoch".
>
> unicorn:~$ printf '%(%c)T\n' 1
> Wed Dec 31 19:00:01 1969
>
> The day of the week for this moment in time will be either Wednesday or
> Thursday, depending on your time zone.
>
> If you want to pass a single argument, you could combine your two
> specifiers into one big one:
>
> unicorn:~$ printf '%(%A  %c)T\n' 1
> Wednesday  Wed Dec 31 19:00:01 1969
>
> This ensures that you're using the same timestamp for the whole thing.

Wow.  Thanks!  I just have to rewrite all of my bash scripts,
replacing external date with printf 's date!

I did not find the printf date incantation within man bash, however these
Emails are highlighted here for future reference.

I am usually using an ISO standard format, 2023.05.02 and 00:27, for
either year/month/date dir names for photo archiving, or appending
time to filenames.

Roger



reply via email to

[Prev in Thread] Current Thread [Next in Thread]