help-bash
[Top][All Lists]
Advanced

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

Re: Problem printing 24 hour times OR a stupid mistake


From: Greg Wooledge
Subject: Re: Problem printing 24 hour times OR a stupid mistake
Date: Sun, 9 Jan 2022 10:22:17 -0500

On Sun, Jan 09, 2022 at 08:13:25AM -0600, Dennis Williamson wrote:
> You should be able to omit the printf and just do
> 
> date -d"$tim12" +"%H%M"

 9. All examples given by the questioner will be broken, misleading,
    wrong, incomplete, and/or not representative of the actual question.

You're probably right that the OP is not showing us enough information
to determine where the conceptual error really is.

I don't have *any* idea why the OP was trying to convert an HH:MM time
to an octal number, for example.  That's just completely beyond my
experience.  Is there some weird algorithm that involves converting a
base 60 number to base 8?  I'm not aware of any.  But that doesn't mean
much.

Or did they simply not know that they can use "%4s" to space-pad a
string to a width of 4?

Or did they think that date +%H might sometimes give a single-digit number,
and then they needed to zero-pad that to two digits?  That's a false
assumption.  date +%H is guaranteed to give two digits of output, never
one digit.  No additional padding is required.

Or is printf a complete red herring (bashphorism 9)?  Are they really
doing some *other* arithmetic with the hour and minute, and are therefore
getting bit by the octal thing?  We've already answered that one (strip
the leading zeroes or force a base 10 interpretation).

Who knows?  It could be anything.



reply via email to

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