JavaScript gmdate
Format a GMT date/time
1 2 3 4 56 7 8 9 1011 12 13 14 1516 17 18 19 | function gmdate (format, timestamp) { // Format a GMT date/time // // version: 1008.1718 // discuss at: http://phpjs.org/functions/gmdate // + original by: Brett Zamir (http://brett-zamir.me) // + input by: Alex // + bugfixed by: Brett Zamir (http://brett-zamir.me) // - depends on: date // * example 1: gmdate('H:m:s \\m \\i\\s \\m\\o\\n\\t\\h', 1062402400); // Return will depend on your timezone // * returns 1: '07:09:40 m is month' 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.date(format, timestamp); } |
Examples
Running
1 | gmdate('H:m:s \\m \\i\\s \\m\\o\\n\\t\\h', 1062402400); // Return will depend on your timezone |
Should return
1 | '07:09:40 m is month' |
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 gmdate goodness in JavaScript.
No comments yet. Be the first!
spread the word:
Use any PHP function in JavaScript
These kind folks have already donated: @HalfWinter, Paulo Freitas, Andros Peña Romo, @andorosu, Raimund Szabo, Nitin Gupta, @nikosdion, Anonymous, Anonymous and Shawn Houser.
<your name here>