w3resource

php.js : gettimeofday() function

gettimeofday() function

The gettimeofday() function is used to get current time information as an array.

Version:

1103.1210

Syntax:

gettimeofday(return_float)

Parameter:

Name Description Required /
Optional
Type
return_float When set to true, a float value instead of an array is returned. Optional Float

Return value:

An associative array. If return_float is set to true, then a float is returned.
Array elements details :

Key Description
sec seconds since the Unix Epoch.
usec Microseconds.
minuteswest Minutes west of Greenwich.
dsttime Type of dst correction

Example of php gettimeofday() function.  

In the following web document gettimeofday() function returns an associative array which contains time information and when the parameter is set to true it returns an float value. Here we use print_r() function to display the details of an array. print_r() belongs to variable.min.js file.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>php.js : gettimeofday() function example</title>
<script type="text/javascript" src="../../phpjs/date/datetime.min.js"> </script>
<script type="text/javascript" src="../../phpjs/variable/variable.min.js"> </script>
</head>
<body>
<h1 style="color: green">php.js : gettimeofday() function example</h1>
<h3>Time information</h3>
<hr />
<script type="text/javascript">
//This is done to make the following JavaScript code compatible to XHTML. <![CDATA[
document.write('gettimeofday()'+'<br/>');
x=gettimeofday();
print_r(x);
document.write('<br/>'+'gettimeofday(true))'+'<br/>');
y=gettimeofday(true);
print_r(y);
//]]>
</script>
</body>
</html>

Output of the function  

gettimeofday()
Array  (      [sec] => 16  [usec] => 62000  [minuteswest] => -330   [dsttime] => 0  ) 
gettimeofday(true))
1309780636.064

Note : Since the current time is not static, therefore the output may vary.

View the example of php.js gettimeofday() function in the browser

Download phpjs.zip

Previous: php.js : getdate() function
Next: php.js: gmdate() function



Share this Tutorial / Exercise on : Facebook and Twitter