[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

converting a number to a date

sig_UVA

9/22/2006 3:13:00 AM

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

5 Answers

WATANABE Hirofumi

9/22/2006 3:32:00 AM

0

Hi,

Hunter Walker <walkerhunter@gmail.com> 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

sig_UVA

9/22/2006 3:53:00 AM

0

WATANABE Hirofumi wrote:
> Hi,
>
> Hunter Walker <walkerhunter@gmail.com> 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-....

Stefan Lang

9/22/2006 2:37:00 PM

0


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

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://De.... Sign up and save your mailbox.

sig_UVA

9/22/2006 2:43:00 PM

0

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

Stefan Lang

9/22/2006 3:29:00 PM

0


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

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://De.... Sign up and save your mailbox.