phpjs
Version:
58 lines (48 loc) • 1.82 kB
Markdown
layout: page
title: "JavaScript time function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/time:562
- /functions/view/time
- /functions/view/562
- /functions/time:562
- /functions/562
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's time
{% codeblock datetime/time.js lang:js https://raw.github.com/kvz/phpjs/master/functions/datetime/time.js raw on github %}
function time () {
// From: http://phpjs.org/functions
// + original by: GeekFG (http://geekfg.blogspot.com)
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: metjay
// + improved by: HKM
// * example 1: timeStamp = time();
// * example 1: timeStamp > 1000000000 && timeStamp < 2000000000
// * returns 1: true
return Math.floor(new Date().getTime() / 1000);
}
{% endcodeblock %}
- [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/datetime/time.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/time.js)
### Example 1
This code
{% codeblock lang:js example %}
timeStamp = time();
timeStamp > 1000000000 && timeStamp < 2000000000
{% endcodeblock %}
Should return
{% codeblock lang:js returns %}
true
{% endcodeblock %}
### Other PHP functions in the datetime extension
{% render_partial _includes/custom/datetime.html %}