ruby datetime

S

Sriram Varahan

Hello,

I have two time objects:

# 2 days ago
time1 = Time.now - 48 * 3600

#=> Sun Jun 21 16:56:33 +0530 2009

time2 = Time.now
#=> Tue Jun 23 16:57:05 +0530 2009

I need to create a third time object which will have the date from time2
and the time from time1.

time3 should be:

#=> Tue Jun 23 16:56:33 +0530 2009

The issue I am facing is how do I extract the date and time to create
the third time.

Any suggestion would be welcome.

Thanks
Sriram.
 
R

Rick DeNatale

Hello,

I have two time objects:

# 2 days ago
time1 =3D Time.now - 48 * 3600

#=3D> =A0Sun Jun 21 16:56:33 +0530 2009

time2 =3D Time.now
#=3D> Tue Jun 23 16:57:05 +0530 2009

I need to create a third time object which will have the date from time2
and the time from time1.

time3 should be:

#=3D> Tue Jun 23 16:56:33 +0530 2009

The issue I am facing is how do I extract the date and time to create
the third time.

Any suggestion would be welcome.


time3 =3D Time.local(time2.year, time2.month, time2.mday, time1.hour,
time1.min, time1. sec, time1.usec)


--=20
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
 
H

Heesob Park

Hi,

2009/6/23 Sriram Varahan said:
Hello,

I have two time objects:

# 2 days ago
time1 =3D Time.now - 48 * 3600

#=3D> =C2=A0Sun Jun 21 16:56:33 +0530 2009

time2 =3D Time.now
#=3D> Tue Jun 23 16:57:05 +0530 2009

I need to create a third time object which will have the date from time2
and the time from time1.

time3 should be:

#=3D> Tue Jun 23 16:56:33 +0530 2009

The issue I am facing is how do I extract the date and time to create
the third time.

Any suggestion would be welcome.
time3 =3D Time.at(time2.to_i/86400*86400+time1.to_f%86400)

Regards,
Park Heesob
 

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

No members online now.

Forum statistics

Threads
474,172
Messages
2,570,933
Members
47,472
Latest member
blackwatermelon

Latest Threads

Top