Skip to content

Ruby – Time in Millis

January 31, 2015

The scenario which i encountered is to convert the date from database and convert it to Time in Millis (Example – 1422720326688)

The reason is the third party API which we use forces us to give the time in mills since unix epoch.

Following is the code snippet which can be used. I love Ruby for the expressive nature.

time = “#{rowDistinct[2]}” #- Date from Database – 2014-12-26 10:35:22 format
dTime = DateTime.parse(time)
aTime = dTime.to_time

aTime.to_i # – This will give the result in 1422720326688 format

Happy Rubying 🙂

Advertisements
No comments yet

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

%d bloggers like this: