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

Re: Date and timestamp conversion



On 4/19/06, Paul Howarth <paul city-fan org> wrote:
> Dan Track wrote:
> > On 4/19/06, Paul Howarth <paul city-fan org> wrote:
> >> Dan Track wrote:
> >>> Hi
> >>>
> >>> Does anyone know how to convert between the `date -s` output to
> >>> timestamp and vice versa. Also does anyone know how to get the
> >>> timestamp for a date period in the past or future?
> >> I don't really understand the question.
> >>
> >> Please give an example of the two formats you want to convert between.
> >>
> >> Paul.
> >>
> > Hi Paul
> > I'd like to convert
> > Wed Apr 19 13:02:16 BST 2006 --> timestamp
> > or
> > timestamp --> Wed Apr 19 13:02:16 BST 2006
> >
> > How would I do the above?
> >
> > Is there a simple script for this?
>
> You still haven't said what a "timestamp" looks like.
>
> If it's an integer representing the number of seconds since 1970-01-01
> 00:00:00 UTC, try this:
>
> $ date --date='Wed Apr 19 13:02:16 BST 2006' '+%s'
> 1145448136
>
> Back again:
> $ TIMESTAMP=1145448136
> $ awk 'BEGIN { print strftime("%a, %d %b %Y %H:%M:%S %z", '$TIMESTAMP')
> }' < /dev/null
> Wed, 19 Apr 2006 13:02:16 +0100
>
>

Thanks everyone for your help.
That's exactly what I was looking for.

Thanks again.
Dan


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