Unix timestamps are a compact way of storing the time and date as a 32-bit integer containing the number of seconds since midnight, January 1, 1970, GMT, also known as the Unix Epoch.
You want to convert a date and time to Unix timestamp.
Use mktime(). It returns an integer containing the number of seconds between the Unix epcoh and the time specified in the argument list.
mktime ([hour [, minute [,second [,month [,day [,year [, is_dst]]]]]]])
| Argument | Meaning |
|---|---|
| hour | Number of the hour |
| minute | Number of the minute |
| second | Number of seconds past the minute |
| month | Number of the month |
| day | Number of the day |
| year | number of the year, can be a two- or four-digit value |
| is_dst | daylight Saving Time; 0 if is; 1 if not; -1 is the default |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN">
<head>
<title>time()</title>
<meta Name="Author" Content="Hann So">
</head>
<body>
<p>
<?php
$seconds = mktime();
echo "$seconds <br />";
echo date("M-d-Y", $seconds), "<br />";
$seconds = mktime(0, 0, 0, 7, 4, 2008);
echo "$seconds <br />";
echo date("M-d-Y", $seconds), "<br />";
echo date("M-d-Y", mktime(0, 0, 0, 7, 32, 8)), "<br />";
?>
</p>
</body>
</html>
|