Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails and JavaScript. Wrong length on unix timestamps

I am developing an application in Javascript using Appcelerator and I need to compare two different UNIX timestamps.

The problem is one gets longer then the other which makes it bigger even though it is not.

The long one is generated via javascript like this:

var d = new Date();

value.httpCacheCreated = d.getTime();

And the result is:

1309443190619

And its human readable value is:

Thu, 30 Jun 2011 14:13:10 gmt

The short one is generated from Rails like this:

current_user.updated_at.to_time.to_i

And the result is:

1309442086

And its human readable value is:

Thu, 30 Jun 2011 13:54:46 gmt

When you look at the human readable the short one is newer but if I compare them, the long one being longer and the comparison fails.

So how can I get the to be the same size?

like image 640
Jonathan Clark Avatar asked Feb 23 '23 17:02

Jonathan Clark


1 Answers

javascript getTime() gives you number of milliseconds while Ruby's Time#to_i gives you number of seconds

just get rid of last 3 digit's in javascript's version and you will have ruby's version

like image 96
keymone Avatar answered Feb 26 '23 08:02

keymone