---
layout: page
title: "JavaScript gmdate function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/gmdate:586
- /functions/view/gmdate
- /functions/view/586
- /functions/gmdate:586
- /functions/586
---
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's gmdate

{% codeblock datetime/gmdate.js lang:js https://raw.github.com/kvz/phpjs/master/functions/datetime/gmdate.js raw on github %}
function gmdate (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: 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);
}
{% endcodeblock %}

 - [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/datetime/gmdate.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/gmdate.js)

### Example 1
This code
{% codeblock lang:js example %}
gmdate('H:m:s \\m \\i\\s \\m\\o\\n\\t\\h', 1062402400); // Return will depend on your timezone
{% endcodeblock %}

Should return
{% codeblock lang:js returns %}
'07:09:40 m is month'
{% endcodeblock %}


### Other PHP functions in the datetime extension
{% render_partial _includes/custom/datetime.html %}
