[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: printf %()T
From: |
Greg Wooledge |
Subject: |
Re: printf %()T |
Date: |
Fri, 28 Apr 2023 08:23:31 -0400 |
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.