converting a number to a date

H

Hunter Walker

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!
 
W

WATANABE Hirofumi

Hi,

Hunter Walker said:
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
 
H

Hunter Walker

WATANABE said:
Hi,



% 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.
 
K

Kevin Olbrich

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!

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
 
H

Hunter Walker

Kevin said:
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?
 
K

Kevin Olbrich

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

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top