UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

61 lines (51 loc) 2.08 kB
--- layout: page title: "JavaScript gmstrftime function" comments: true sharing: true footer: true alias: - /functions/view/gmstrftime:780 - /functions/view/gmstrftime - /functions/view/780 - /functions/gmstrftime:780 - /functions/780 --- <!-- Generated by Rakefile:build --> A JavaScript equivalent of PHP's gmstrftime {% codeblock datetime/gmstrftime.js lang:js https://raw.github.com/kvz/phpjs/master/functions/datetime/gmstrftime.js raw on github %} function gmstrftime (format, timestamp) { // From: http://phpjs.org/functions // + original by: Brett Zamir (http://brett-zamir.me) // + input by: Alex // + bugfixed by: Brett Zamir (http://brett-zamir.me) // - depends on: strftime // * example 1: gmstrftime("%A", 1062462400); // * returns 1: 'Tuesday' var dt = ((typeof timestamp === 'undefined') ? new Date() : // Not provided (typeof timestamp === 'object') ? new Date(timestamp) : // Javascript Date() new Date(timestamp * 1000) // UNIX timestamp (auto-convert to int) ); timestamp = Date.parse(dt.toUTCString().slice(0, -4)) / 1000; return this.strftime(format, timestamp); } {% endcodeblock %} - [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/datetime/gmstrftime.js) Please note that php.js uses JavaScript objects as substitutes for PHP arrays, they are the closest match to this hashtable-like data structure. Please also note that php.js offers community built functions and goes by the [McDonald's Theory](https://medium.com/what-i-learned-building/9216e1c9da7d). We'll put online functions that are far from perfect, in the hopes to spark better contributions. Do you have one? Then please just: - [Edit on GitHub](https://github.com/kvz/phpjs/edit/master/functions/datetime/gmstrftime.js) ### Example 1 This code {% codeblock lang:js example %} gmstrftime("%A", 1062462400); {% endcodeblock %} Should return {% codeblock lang:js returns %} 'Tuesday' {% endcodeblock %} ### Other PHP functions in the datetime extension {% render_partial _includes/custom/datetime.html %}