phpjs
Version:
49 lines (41 loc) • 1.46 kB
Markdown
layout: page
title: "JavaScript filemtime function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/filemtime:838
- /functions/view/filemtime
- /functions/view/838
- /functions/filemtime:838
- /functions/838
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's filemtime
{% codeblock filesystem/filemtime.js lang:js https://raw.github.com/kvz/phpjs/master/functions/filesystem/filemtime.js raw on github %}
function filemtime (file) {
// + original by: Ole Vrijenhoek (http://www.nervous.nl/)
// + bugfixed by: Brett Zamir (http://brett-zamir.me)
// - depends on: get_headers
// % note 1: Looks for Last-Modified in response header.
// * example 1: filemtime('http://www.un.org');
// * returns 1: 1241532483
var headers = {};
headers = this.get_headers(file, 1);
return (headers && headers['Last-Modified'] && Date.parse(headers['Last-Modified']) / 1000) || false;
}
{% endcodeblock %}
- [view on github](https://github.com/kvz/phpjs/blob/master/functions/filesystem/filemtime.js)
- [edit on github](https://github.com/kvz/phpjs/edit/master/functions/filesystem/filemtime.js)
### Example 1
This code
{% codeblock lang:js example %}
filemtime('http://www.un.org');
{% endcodeblock %}
Should return
{% codeblock lang:js returns %}
1241532483
{% endcodeblock %}
### Other PHP functions in the filesystem extension
{% render_partial _includes/custom/filesystem.html %}