[Top][All Lists]

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

Re: date +%s ignores TZ

From: Bob Proulx
Subject: Re: date +%s ignores TZ
Date: Fri, 29 Feb 2008 15:33:24 -0700
User-agent: Mutt/1.5.13 (2006-08-11)

Brian Dessent wrote:
> Jan Engelhardt wrote:
> > I wanted to get the number of seconds since the start of the day.
> > 
> >         echo $[`date +%s` % 86400];
> How about:
> echo $[$(date +%s) - $(date -d '' +%s)]

That works most of the time and if I were never to run this at
midnight I would do just what you suggest here and wouldn't worry
about it further.  But Jan specifically mentioned wanting midnight.
That made me avoid suggesting that case.  If this needs to be robust
at midnight then it needs one date invocation which needs more work.

The problem is that the first date might execute at midnight minus one
second.  The second date might execute at midnight, which is the next
day.  If that happens then a negative value would result because the
start of the day subtracted off would be the start of the next day.
Therefore the need to get the time once only.


reply via email to

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