in reply to Converting from "time" into a nice string?

Check out strftime in the POSIX module. Allows you to format (more or less) how you want.

G. Wade

Replies are listed 'Best First'.
Re^2: Converting from "time" into a nice string?
by ultranerds (Hermit) on Nov 14, 2008 at 13:36 UTC
    Thanks.

    Another quick question if I may :)

    The current server is setup as PST.

    ultranerds@east ~ $ date
    Fri Nov 14 05:33:17 PST 2008

    How would I go about increasing (and decreasing, depending on the timezone I wish to show the date stamp in), the output from PST, to say GMT , or another timezone.

    I guess its something like:

    hours difference from GMT * 60 * 60 +(or -) the timestamp

    would that be about right?

    TIA!

    Andy

      Presuming your libc plays along, in theory you can diddle $ENV{TZ} and get the right representation from the same time_t value. Otherwise you're going to want to look into DateTime and let it and DateTime::TimeZone convert things around for you.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

        Thanks for the reply Fletch.

        Would this work ok with an existing string though?

        Basically - the "time" (i.e 1226667500) is stored in the DB - at server time (in this case, PST - this will NEVER change, so it needs to be saved like that I guess).

        Then, I need (based on where the user is located), to convert that time - to their local timezone (in my case, I'm in the UK)

        TIA

        Andy