Reputation: 4160
i'm using Date().getTime() to set time of activity of user in my app. But in two different machine (mobile and pc)seems return different value. If i get time first from mobile and after from pc, the value returned from Date().getTime() of mobile must be minor of value of pc but is viceversa!!
This is the method to set time:
var user = this.get("objectId");
var lastactivity=Math.round(new Date().getTime()/1000);
this.set("lastactivity",lastactivity);
var User = Parse.Object.extend("User");
var query = new Parse.Query(User);
query.get(user, {
success: function(object) {
console.log(object);
object.set("lastactivity", lastactivity);
object.save();
},
error: function(object, error) {
// handle error
}
});
Upvotes: 0
Views: 276
Reputation: 15497
try setting hours to 0000
var d = new Date();
var myDate = new Date(d.setHours(0,0,0,0));
now use this date, you will get same time at all places. In your case you can try this
var user = this.get("objectId");
var lastactivity=Math.round(myDate.getTime()/1000);
Upvotes: -2
Reputation: 29083
new Date()
is only as accurate and the clocks on each of these devices. If the devices themselves aren't perfectly sync'd it is expected that you'll get different values. Generally speaking, it's best to assign timestamps on the serverside when data is posted... if all clients are talking to the same server, then you don't need to worry about the clocks on your users' devices.
Upvotes: 3