UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

63 lines (55 loc) 1.95 kB
--- layout: page title: "JavaScript date_default_timezone_set function" comments: true sharing: true footer: true alias: - /functions/view/date_default_timezone_set:584 - /functions/view/date_default_timezone_set - /functions/view/584 - /functions/date_default_timezone_set:584 - /functions/584 --- <!-- Generated by Rakefile:build --> A JavaScript equivalent of PHP's date_default_timezone_set {% codeblock datetime/date_default_timezone_set.js lang:js https://raw.github.com/kvz/phpjs/master/functions/datetime/date_default_timezone_set.js raw on github %} function date_default_timezone_set (tz) { // http://kevin.vanzonneveld.net // + original by: Brett Zamir (http://brett-zamir.me) // - depends on: timezone_abbreviations_list // % note 1: Uses global: php_js to store the default timezone // * example 1: date_default_timezone_set('unknown'); // * returns 1: 'unknown' var tal = {}, abbr = '', i = 0; // BEGIN REDUNDANT this.php_js = this.php_js || {}; // END REDUNDANT // PHP verifies that the timezone is valid and also sets this.php_js.currentTimezoneOffset and this.php_js.currentTimezoneDST if so tal = this.timezone_abbreviations_list(); for (abbr in tal) { for (i = 0; i < tal[abbr].length; i++) { if (tal[abbr][i].timezone_id === tz) { this.php_js.default_timezone = tz; return true; } } } return false; } {% endcodeblock %} - [view on github](https://github.com/kvz/phpjs/blob/master/functions/datetime/date_default_timezone_set.js) - [edit on github](https://github.com/kvz/phpjs/edit/master/functions/datetime/date_default_timezone_set.js) ### Example 1 This code {% codeblock lang:js example %} date_default_timezone_set('unknown'); {% endcodeblock %} Should return {% codeblock lang:js returns %} 'unknown' {% endcodeblock %} ### Other PHP functions in the datetime extension {% render_partial _includes/custom/datetime.html %}