w3resource

php.js : getdate() function

getdate() function

The getdate() function accepts a timestamp and returns an associative array that contains the date and time information.

Version:

1103.1210

Syntax:

getdate(timestamp)

Parameter:

Name Description Required /
Optional
Type
timestamp Unix timestamp.
Default value : current local time.
Required String

Return value:

Details are as follows:

Key Description Example returned values
seconds Numeric value of seconds. 0 to 59
minutes Numeric value of minutes. 0 to 59
hours Numeric value of hours. 0 to 23
mday Numeric value of the day of the month. 1 to 31
wday Numeric value of the day of the week. 0(for Sunday) through 6 (for Saturday)
mon Numeric value of a month. 1 through 12
year Four-digit numeric value of a year. Examples: 1999 or 2003
yday Numeric value of the day of the year. 0 through 365
weekday Full name of the day of the week. Sunday through Saturday
month Full name of a month. January through December
0 Seconds since the Unix Epoch, similar to the values returned by time() and used by date(). System Dependent, typically -2147483648 through 2147483647

Value Type: Array

Example of php.js getdate() function:

In the following web document getdate() function returns an associative array which contains date and time information. 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 : getdate() function example</title>
<script type="text/javascript" src="datetime.min.js"> </script>
<script type="text/javascript" src="../../phpjs/variable/variable.min.js"></script>
</head>
<body>
<h1 style="color: green">php.js : getdate() function example</h1>
<h3>Date/time information</h3>
<hr />
<script type="text/javascript">
//This is done to make the following JavaScript code compatible to XHTML. <![CDATA[
x=getdate(1055901520);
print_r(x);
document.write('getdate(date("U"))')+'<br/>');
y=getdate(date("U"));
print_r(y);
//]]>
</script>
</body>
</html>

Output of the function:

getdate(1055901520) Array ( [seconds] => 40 [minutes] => 28 [hours] => 7 [mday] => 18 [wday] => 3 [mon] => 6 [year] => 2003 [yday] => 168 [weekday] => Wednesday [month] => June [0] => 1055901520 ) getdate(date("U")) Array ( [seconds] => 9 [minutes] => 26 [hours] => 18 [mday] => 22 [wday] => 5 [mon] => 7 [year] => 2011 [yday] => 202 [weekday] => Friday [month] => July [0] => 1311339369 ) 

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

Download phpjs.zip

Previous: php.js: date() function
Next: php.js : gettimeofday() function



Follow us on Facebook and Twitter for latest update.