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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With