converting a number to a date

Discussion in 'Ruby' started by Hunter Walker, Sep 22, 2006.

  1. My XML request returned a date field as a "string" with the value of
    1158364800000
    Does Ruby have a function to turn this into a date?

    Thank you!

    --
    Posted via http://www.ruby-forum.com/.
    Hunter Walker, Sep 22, 2006
    #1
    1. Advertising

  2. Hi,

    Hunter Walker <> writes:

    > My XML request returned a date field as a "string" with the value of
    > 1158364800000
    > Does Ruby have a function to turn this into a date?


    % ruby -e 'p Time.at("1158364800000".to_i / 1000.0).utc'
    Sat, Sep 16 2006 00:00:00 +0000

    --
    eban
    WATANABE Hirofumi, Sep 22, 2006
    #2
    1. Advertising

  3. WATANABE Hirofumi wrote:
    > Hi,
    >
    > Hunter Walker <> writes:
    >
    >> My XML request returned a date field as a "string" with the value of
    >> 1158364800000
    >> Does Ruby have a function to turn this into a date?

    >
    > % ruby -e 'p Time.at("1158364800000".to_i / 1000.0).utc'
    > Sat, Sep 16 2006 00:00:00 +0000


    This helps a lot. Thank you!


    Now we'll see if I can do some math with it.

    --
    Posted via http://www.ruby-forum.com/.
    Hunter Walker, Sep 22, 2006
    #3
  4. On Friday, September 22, 2006, at 12:13 PM, Hunter Walker wrote:
    >My XML request returned a date field as a "string" with the value of
    >1158364800000
    >Does Ruby have a function to turn this into a date?
    >
    >Thank you!
    >
    >--
    >Posted via http://www.ruby-forum.com/.
    >


    You can, if you have any idea how that date is being encoded. It
    doesn't seem like a timestamp, and it's not the format a Date or
    DateTime object uses.

    _Kevin
    www.sciwerks.com

    --
    Posted with http://DevLists.com. Sign up and save your mailbox.
    Kevin Olbrich, Sep 22, 2006
    #4
  5. Kevin Olbrich wrote:
    > On Friday, September 22, 2006, at 12:13 PM, Hunter Walker wrote:
    >>My XML request returned a date field as a "string" with the value of
    >>1158364800000
    >>Does Ruby have a function to turn this into a date?
    >>
    >>Thank you!
    >>
    >>--
    >>Posted via http://www.ruby-forum.com/.
    >>

    >
    > You can, if you have any idea how that date is being encoded. It
    > doesn't seem like a timestamp, and it's not the format a Date or
    > DateTime object uses.
    >
    > _Kevin
    > www.sciwerks.com


    What format do I need for the Date or DateTime object?


    --
    Posted via http://www.ruby-forum.com/.
    Hunter Walker, Sep 22, 2006
    #5
  6. On Friday, September 22, 2006, at 11:43 PM, Hunter Walker wrote:
    >Kevin Olbrich wrote:
    >> On Friday, September 22, 2006, at 12:13 PM, Hunter Walker wrote:
    >>>My XML request returned a date field as a "string" with the value of
    >>>1158364800000
    >>>Does Ruby have a function to turn this into a date?
    >>>
    >>>Thank you!
    >>>
    >>>--
    >>>Posted via http://www.ruby-forum.com/.
    >>>

    >>
    >> You can, if you have any idea how that date is being encoded. It
    >> doesn't seem like a timestamp, and it's not the format a Date or
    >> DateTime object uses.
    >>
    >> _Kevin
    >> www.sciwerks.com

    >
    >What format do I need for the Date or DateTime object?
    >
    >
    >--
    >Posted via http://www.ruby-forum.com/.
    >


    There are a number of ways to parse dates and times. The most basic
    would be to use a unix timestamp (integer) and then just use the
    Time.at(value) function.

    you can also use ParseDate, or DateTime.parse, or the Chronic gem.

    I guess my real question is:
    What does "1158364800000" represent? It is unlike any time format I've seen.


    _Kevin
    www.sciwerks.com

    --
    Posted with http://DevLists.com. Sign up and save your mailbox.
    Kevin Olbrich, Sep 22, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Candy
    Replies:
    2
    Views:
    1,149
    Janaka
    Feb 18, 2004
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,226
    Michael Borgwardt
    May 30, 2004
  3. Replies:
    5
    Views:
    98,537
    vongeuca
    May 4, 2011
  4. ruds
    Replies:
    3
    Views:
    5,567
    Daniel Pitts
    Jan 10, 2007
  5. Jef Driesen

    Converting date string to a number

    Jef Driesen, Jul 18, 2007, in forum: C++
    Replies:
    8
    Views:
    658
    Jim Langston
    Jul 20, 2007
Loading...

Share This Page