Rails and JavaScript. Invalid Unix Timestamp Length

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

The problem is that it becomes longer than the other, which makes it bigger, even if it is not.

Long is generated via javascript as follows:

var d = new Date(); value.httpCacheCreated = d.getTime(); 

And the result:

 1309443190619 

And its human-readable meaning:

 Thu, 30 Jun 2011 14:13:10 gmt 

Short is generated from Rails as follows:

 current_user.updated_at.to_time.to_i 

And the result:

 1309442086 

And its human-readable meaning:

 Thu, 30 Jun 2011 13:54:46 gmt 

When you look at something readable by a person, the short one is newer, but if I compare them, the long one is long and the comparison is not performed.

So how can I get the same size?

+4
source share
1 answer

javascript getTime () gives you the number of milliseconds, while Ruby Time # to_i gives you the number of seconds

just get rid of the last 3 digits in javascript version and you will have ruby โ€‹โ€‹version

+8
source

All Articles