help-bash
[Top][All Lists]
Advanced

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

Re: Problem printing 24 hour times


From: ikhxcsz7y xmbott
Subject: Re: Problem printing 24 hour times
Date: Sat, 8 Jan 2022 16:17:56 +0100

strip leading 0 away

On Sat, Jan 8, 2022, 16:16 Chris Elvidge <celvidge001@gmail.com> wrote:

> Given tim12="7:00 am" and tim24=$(date -d"$tim12" +"%H%M")
>
> printf '%04d' "$tim24" prints 0488; '%04o' will output 0700
>
> But if tim12="7:00 pm" and tim24=$(date -d"$tim12" +"%H%M")
> '%04d' gives the correct output 1900 but '%04o' gives 3554
>
> I have got round the problem with tim24=$(date -d"$tim12" +"%-H%M") i.e.
> stripping leading zeros, but is there any way to force printf to
> recognise 0700 as a decimal number?
>
> --
> Regards
> Chris Elvidge
> England
>
>
>


reply via email to

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