javascript - Server and browser date difference -


when run app in browser shows last saved now or last saved 2 mins ago problem may b different machine machine.

let's machine current time 13:30 , other machine time 13:34.. want difference..my app showing in machine last saved now , in other machine last saved 4 mins ago.. need difference..any suggestion please?

updated can browser time like:

var d = new date(); var hrs = d.gethours(); var min = d.getminutes(); var sec = d.getseconds(); if (hrs < 10) {     hrs = '0' + hrs; }  if (min < 10) {     min = '0' + min; }  if (sec < 10) {     sec = '0' + sec; }  var system_date = hrs + ":" + min + ":" + sec; 

not getting idea time have fetch , how?

the solution not use local computer date. instead, return timespan server indicates how long since operation occurred. timespan based on server time.

for example, if save @ 12:00 on server-time clock set 12:05, if use server date of 12:00 , compare local date, 12:05, '5 minutes ago' when instant.

so fix it, return server timespan. number of seconds. can convert client-side 'x minutes ago' or 'x seconds ago' or 'x hours ago'.

alternatively, calculate string on server , return client.


Comments