php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #14115 localtime() gives wrong year and month
Submitted: 2001-11-19 08:37 UTC Modified: 2001-11-19 08:56 UTC
From: kapp at bigping dot de Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.0.6 OS: SuSE Linux 7.1
Private report: No CVE-ID: None
 [2001-11-19 08:37 UTC] kapp at bigping dot de
/* 

Output from my attached PHP script:

-output starts here-
Server script path: /httpd/kunden/admbping/de/bigping/www/localtime_y2k.php


original 'localtime()' function:

tm_sec => 41
tm_min => 14
tm_hour => 14
tm_mday => 19
tm_mon => 10
tm_year => 101
tm_wday => 1
tm_yday => 322
tm_isdst => 0

my 'localtime_y2k()' function:

tm_sec => 41
tm_min => 14
tm_hour => 14
tm_mday => 19
tm_mon => 11
tm_year => 2001
tm_wday => 1
tm_yday => 322
tm_isdst => 0
-output ends here-


'date' command in bash:

localhost:/httpd/kunden/admbping/de/bigping/www # date
Mon Nov 19 14:14:57 CET 2001

*/

<?
function localtime_y2k ($time, $is_ass) {
	$t_arr = localtime ($time, $is_ass);
	if ($is_ass == 0) {
		$t_arr[5] = $t_arr[5] + 1900;
		$t_arr[4] = $t_arr[4] + 1;
	}
	if ($is_ass == 1) {
		$t_arr["tm_year"] = $t_arr["tm_year"] + 1900;
		$t_arr["tm_mon"] = $t_arr["tm_mon"] + 1;
	}
	return $t_arr;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html lang=en_us>
	<head>
		<meta http-equiv=content-type content="text/html; charset=iso-8859-1">
		<title>
			Untitled
		</title>
	</head>
	<body bgcolor="#FFFFFF">
<?
$the_time = time();
$timearray_old = localtime ($the_time, 1);
$timearray = localtime_y2k ($the_time, 1);
echo "Server script path: ".getenv ("SCRIPT_FILENAME");
echo "<br><br><br>original 'localtime()' function:<br><br>";
while (list ($key, $val) = each ($timearray_old)) {
    echo "$key => $val<br>";
}
echo "<br><br><br>my 'localtime()' function:<br><br>";
while (list ($key, $val) = each ($timearray)) {
    echo "$key => $val<br>";
}
?> 
	</body>
</html>

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-19 08:43 UTC] rasmus@php.net
tm_year is defined to be the number of years since 1900, so 101 is correct, and tm_mon starts with January = 0.  This is to match the libc function of the same name.  Do a "man localtime" on your system for proof.
 [2001-11-19 08:50 UTC] hholzgra@php.net
the manual does tell about the 1900 offset
for tm_year but not about tm_month starting
at 0
 [2001-11-19 08:56 UTC] hholzgra@php.net
added a note to phpdoc cvs
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Sep 09 05:01:27 2024 UTC