JavaScript gmstrftime
Format a GMT/UCT time/date according to locale settings
1 2 3 4 56 7 8 9 1011 12 13 14 1516 17 18 19 | function gmstrftime (format, timestamp) { // Format a GMT/UCT time/date according to locale settings // // version: 910.813 // discuss at: http://phpjs.org/functions/gmstrftime // + 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); } |
Examples
Running
1 | gmstrftime("%A", 1062462400); |
Should return
1 | 'Tuesday' |
Dependencies
In order to use this function, you also need:
Open syntax issues
php.js uses JsLint to help us keep our code consistent and prevent some common bugs.
Eventually we want all code to pass or at least take into consideration most fixes suggested by JsLint, following this JsLint configuration we’ve decided on.
Authors
Thanks to the following developers, you get to have gmstrftime goodness in JavaScript.
No comments yet. Be the first!
spread the word:
Use any PHP function in JavaScript
These kind folks have already donated: Anonymous and Shawn Houser.
<your name here>