0

I have pcap import and read facility in my project. I have handling timezone in my project. Imported pcap is not read/display if I changed my timezone from GMT to other Asia/Kolkota.

How can I handle timezone issue in javascript. I am storing the value into the database is 2013-05-07 00:04:23.435751-06.

it should be handled in all timezone. thanks in advance

0

1 Answer 1

0

I wish you are looking for this beautiful documentation. Thanks.

Update try this:

  var str= '2013-05-07 00:04:23.435751-06';
  var n = str.slice( -3 );
  var time = str.replace(" ","T");
  time = time.slice(0, -3);
  alert(calcTime(time, n));

  function calcTime(time, offset) {

  // create Date object for current location
  d = new Date(Date.parse(time));

  // convert to msec
  // add local time zone offset
  // get UTC time in msec
  utc = d.getTime() + (d.getTimezoneOffset() * 60000);

  // create new Date object for different city
  // using supplied offset
  nd = new Date(utc + (3600000*offset));

  // return time as a string
  return "The Time is " + nd.toLocaleString();

  }
7
  • Thank you rony, It is helpful me but it is not working for the time - 2013-05-07 00:04:23.435751-06 which i used for timezone conversion of this value. Another thing how can I get machine offset to use in above example. I stored first packet time in database inthe form of ex. - 2013-05-07 00:04:23.435751-06 and then in UI it get converted using Date.parse and other js function for timezone. but it isnot workable for different timezone. May 7, 2013 at 10:35
  • ok, in this time string 2013-05-07 00:04:23.435751-06, -06 is the offset. So, extract this form this string. And replacing this "white-space" with "T" and removing -06 from the time string make a string like this: 2013-05-07T00:04:23.435751 and then this code will be worked d = new Date(Date.parse('2013-05-07T00:04:23.435751'))
    – rony36
    May 7, 2013 at 10:57
  • had updated my answer. Try it now. :)
    – rony36
    May 7, 2013 at 11:13
  • Thank you rony. I see it is working fine now but I need to do more debug on it. thanks a ton for your help to sort this one. May 7, 2013 at 13:33
  • Rony - Previous problem is fixed but now issue with current timezone - suppose for the above pcap file I imported it from UTC+5.5 timezone and by your code I will convert it in local timezone and see the data but when I am in UTC timezone and access (above) already imported file, in that case I cannot see/read the data because in database the entry for both timezone is same and when I changed my timezone it will get change the local timezone but database value of first packet remain same. Please advice May 7, 2013 at 13:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.