CakePHP Timezone Helper with jQuery


If you are using the updated Timezone Helper for CakePHP you can help your visitors to select a right timezone by guessing their system’s timezone and preselecting an option in the drop-down list. Insert this scriptBlock in your view:
$(document).ready(function() {
  function get_time_zone_offset( ) {
    var visitortime = new Date();
    var visitortimezone = -visitortime.getTimezoneOffset() / 60;
    var val = (visitortimezone > 0) ?
      "+" + visitortimezone.toString() + ".0":
      visitortimezone.toString() + ".0";
 
    return val;
  }
  $("#UserTimezone").val( get_time_zone_offset() );
});

This entry was posted in . Bookmark the permalink.

Leave a Reply