UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

58 lines (47 loc) 1.85 kB
--- layout: page title: "JavaScript microtime function" comments: true sharing: true footer: true alias: - /functions/view/microtime:472 - /functions/view/microtime - /functions/view/472 - /functions/microtime:472 - /functions/472 --- <!-- Generated by Rakefile:build --> A JavaScript equivalent of PHP's microtime {% codeblock datetime/microtime.js lang:js https://raw.github.com/kvz/phpjs/master/functions/datetime/microtime.js raw on github %} function microtime (get_as_float) { // From: http://phpjs.org/functions // + original by: Paulo Freitas // * example 1: timeStamp = microtime(true); // * example 1: timeStamp > 1000000000 && timeStamp < 2000000000 // * returns 1: true var now = new Date().getTime() / 1000; var s = parseInt(now, 10); return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s; } {% endcodeblock %} - [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/datetime/microtime.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/microtime.js) ### Example 1 This code {% codeblock lang:js example %} timeStamp = microtime(true); 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 %}