Ruby’s Time.now

December 2, 2008 § 2 Comments

I really miss Ruby’s Time.now.to_i, too bad Python does not have something as convenient.

So I created one:

import datetime
import time

class TimeUtil():
	@classmethod
	def to_i(cls, t=None):
		if t is None:
			t = datetime.datetime.utcnow()
		return time.mktime(t.timetuple())
Advertisements

Tagged: , , ,

§ 2 Responses to Ruby’s Time.now

  • Larry Price says:

    Just out of curiosity, what does this do for you that

    int(time.time())

    doesn’t?

  • didip says:

    @ Larry Price:

    1. On my project, all time instance are in datetime format. That information is of course absent in this blog.

    2. But, to tell you the truth, somehow I just didn’t think about doing int(time.time()). Thanks for pointing that out.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Ruby’s Time.now at RAPD.

meta

%d bloggers like this: