Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > getting a timestamp

Reply
Thread Tools

getting a timestamp

 
 
jp
Guest
Posts: n/a
 
      11-19-2009
Hi,

I would like to get a timestamp from a Date object. What is the best
aproach for this?

thank you
 
Reply With Quote
 
 
 
 
Reid Thompson
Guest
Posts: n/a
 
      11-19-2009
jp wrote:
> Hi,
>
> I would like to get a timestamp from a Date object. What is the best
> aproach for this?
>
> thank you
>

I think you want a DateTime or Time object, I believe a Date object only represents a date, not a date and
time unless perhaps 'date at midnight' counts.



 
Reply With Quote
 
 
 
 
Mike Stok
Guest
Posts: n/a
 
      11-19-2009

On Nov 18, 2009, at 10:10 PM, jp wrote:

> Hi,
>
> I would like to get a timestamp from a Date object. What is the best
> aproach for this?
>
> thank you


I'm not sure if this is the most effective, but

d = Date.new(2009, 11, 1
ts = d.strftime('%s').to_i

seems to work for me, giving the timestamp for 2009-11-10 00:00:00 GMT

Hope this helps,

Mike

--

Mike Stok <>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.





 
Reply With Quote
 
Sven Schott
Guest
Posts: n/a
 
      11-19-2009
[Note: parts of this message were removed to make it a legal post.]

Don't know if this is what you're looking for but whenever I need a
serial-style timestamp (like for a filename). I just do this:

Time.now.strftime("%Y%m%d%H%M%S")

On Thu, Nov 19, 2009 at 2:19 PM, Reid Thompson <>wrote:

> jp wrote:
>
>> Hi,
>>
>> I would like to get a timestamp from a Date object. What is the best
>> aproach for this?
>>
>> thank you
>>
>> I think you want a DateTime or Time object, I believe a Date object only

> represents a date, not a date and time unless perhaps 'date at midnight'
> counts.
>
>
>
>


 
Reply With Quote
 
jp
Guest
Posts: n/a
 
      11-19-2009
On 19 Nov, 03:31, Sven Schott <sven.sch...@gmail.com> wrote:
> [Note: *parts of this message were removed to make it a legal post.]
>
> Don't know if this is what you're looking for but whenever I need a
> serial-style timestamp (like for a filename). I just do this:
>
> Time.now.strftime("%Y%m%d%H%M%S")
>
> On Thu, Nov 19, 2009 at 2:19 PM, Reid Thompson <reid.thomp...@ateb.com>wrote:
>
>
>
> > jp wrote:

>
> >> Hi,

>
> >> I would like to get a timestamp from a Date object. What is the best
> >> aproach for this?

>
> >> thank you

>
> >> *I think you want a DateTime or Time object, I believe a Date objectonly

> > represents a date, not a date and time unless perhaps 'date at midnight'
> > counts.


Hi,

It's enough to have the milliseconds since a given date in the past,
for example java has this:
http://java.sun.com/j2se/1.5.0/docs/....html#getTime()

It's there anything comparable in Ruby?

Thanks

 
Reply With Quote
 
Reid Thompson
Guest
Posts: n/a
 
      11-19-2009
jp wrote:
> On 19 Nov, 03:31, Sven Schott <sven.sch...@gmail.com> wrote:
>> [Note: parts of this message were removed to make it a legal post.]
>>
>> Don't know if this is what you're looking for but whenever I need a
>> serial-style timestamp (like for a filename). I just do this:
>>
>> Time.now.strftime("%Y%m%d%H%M%S")
>>
>> On Thu, Nov 19, 2009 at 2:19 PM, Reid Thompson <reid.thomp...@ateb.com>wrote:
>>
>>
>>
>>> jp wrote:
>>>> Hi,
>>>> I would like to get a timestamp from a Date object. What is the best
>>>> aproach for this?
>>>> thank you
>>>> I think you want a DateTime or Time object, I believe a Date object only
>>> represents a date, not a date and time unless perhaps 'date at midnight'
>>> counts.

>
> Hi,
>
> It's enough to have the milliseconds since a given date in the past,
> for example java has this:
> http://java.sun.com/j2se/1.5.0/docs/....html#getTime()
>
> It's there anything comparable in Ruby?
>
> Thanks
>
>

maybe...
http://www.ruby-forum.com/topic/78420

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      11-19-2009
2009/11/19 jp <>:
> On 19 Nov, 03:31, Sven Schott <sven.sch...@gmail.com> wrote:
>> [Note: =A0parts of this message were removed to make it a legal post.]
>>
>> Don't know if this is what you're looking for but whenever I need a
>> serial-style timestamp (like for a filename). I just do this:
>>
>> Time.now.strftime("%Y%m%d%H%M%S")
>>
>> On Thu, Nov 19, 2009 at 2:19 PM, Reid Thompson <reid.thomp...@ateb.com>w=

rote:
>>
>>
>>
>> > jp wrote:

>>
>> >> Hi,

>>
>> >> I would like to get a timestamp from a Date object. What is the best
>> >> aproach for this?

>>
>> >> thank you

>>
>> >> =A0I think you want a DateTime or Time object, I believe a Date objec=

t only
>> > represents a date, not a date and time unless perhaps 'date at midnigh=

t'
>> > counts.

>
> Hi,
>
> It's enough to have the milliseconds since a given date in the past,
> for example java has this:
> http://java.sun.com/j2se/1.5.0/docs/....html#getTime()
>
> It's there anything comparable in Ruby?


Hint: there is documentation...

irb(main):001:0> Time.now.to_i
=3D> 1258647502
irb(main):002:0> Time.at(0)
=3D> 1970-01-01 01:00:00 +0100
irb(main):003:0> Time.at(0).to_i
=3D> 0

Cheers

robert


--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      11-19-2009
2009/11/19 Robert Klemme <>:
> 2009/11/19 jp <>:
>> On 19 Nov, 03:31, Sven Schott <sven.sch...@gmail.com> wrote:
>>> [Note: =A0parts of this message were removed to make it a legal post.]
>>>
>>> Don't know if this is what you're looking for but whenever I need a
>>> serial-style timestamp (like for a filename). I just do this:
>>>
>>> Time.now.strftime("%Y%m%d%H%M%S")
>>>
>>> On Thu, Nov 19, 2009 at 2:19 PM, Reid Thompson <reid.thomp...@ateb.com>=

wrote:
>>>
>>>
>>>
>>> > jp wrote:
>>>
>>> >> Hi,
>>>
>>> >> I would like to get a timestamp from a Date object. What is the best
>>> >> aproach for this?
>>>
>>> >> thank you
>>>
>>> >> =A0I think you want a DateTime or Time object, I believe a Date obje=

ct only
>>> > represents a date, not a date and time unless perhaps 'date at midnig=

ht'
>>> > counts.

>>
>> Hi,
>>
>> It's enough to have the milliseconds since a given date in the past,
>> for example java has this:
>> http://java.sun.com/j2se/1.5.0/docs/....html#getTime()
>>
>> It's there anything comparable in Ruby?

>
> Hint: there is documentation...
>
> irb(main):001:0> Time.now.to_i
> =3D> 1258647502
> irb(main):002:0> Time.at(0)
> =3D> 1970-01-01 01:00:00 +0100
> irb(main):003:0> Time.at(0).to_i
> =3D> 0


PS: I forgot

irb(main):007:0> t=3DTime.now
=3D> 2009-11-19 17:20:25 +0100
irb(main):008:0> t.to_i
=3D> 1258647625
irb(main):009:0> t.to_f
=3D> 1258647625.44141
irb(main):010:0> t.usec
=3D> 441411

Cheers

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: getting current timestamp in micro secs Ian Collins C Programming 20 09-19-2008 03:11 PM
getting current timestamp Neel C++ 2 09-19-2008 03:32 AM
Re: getting current timestamp in micro secs Richard Bos C Programming 3 09-18-2008 04:27 PM
Getting file timestamp from url mhearne808[insert-at-sign-here]gmail[insert-dot-here]com Python 2 11-18-2007 01:37 AM
Getting a precise timestamp Ruby 2 07-31-2006 06:16 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57