3

I just want to find time difference between user's time and server side time. like what time is user having on his system and what's the value coming from database. i have got it approximately. but now my problem is what if user is from difference time zone rather then the value is coming from database? So now i just wantto find the exact difference by managing their time zones. Here i am putting my sample code and the values i am getting with their formats.

    var studentSessionStartTimeDate = that._sessionData.studentSession.dtStart; //date with time from db
    var splitTimeDate = studentSessionStartTimeDate.split(' ');
    var oldDate = splitTimeDate[0]; // split date different
    var dateold = new Date(oldDate).getTime(); //convert date into milliseconds
    var time=that._sessionData.studentSession.start;  // User's exact start time from db
    var convertedTime=(Number(time.split(':')[0])*60+Number(time.split(':')[1]))*1000;  // converted time in milliseconds
    var sessionStartTime = dateold+convertedTime;  // db time and date value in milliseconds
    var systemTime = new Date().getTime();   // user's system time value in milliseconds
    var timeDiff = sessionStartTime - systemTime; // now i want this time diff to be exact but it is not calculating the zone difference

now if someone want i can get utc Offset from db also, but how can i get differnce? please help guys its urgent for me. Any help would be appreciated.

4

1 回答 1

0

您可以使用以下代码获取浏览器时区:

新的 Date().getTimezoneOffset();

于 2012-09-27T03:23:33.803 回答