time

(PHP 3, PHP 4, PHP 5)

time -- Возвращает текущую метку времени

Описание

int time ( void )

Возвращает количество секунд, прошедших с начала Эпохи Unix (The Unix Epoch, 1 января 1970, 00:00:00 GMT) до текущего времени.

См. также описание функций date() и microtime().



time
send at mail dot 2aj dot net
08-Jun-2006 11:58
If you want to create a "rounded" time stamp, for example, to the nearest 15 minutes use this as a reference:

<?php
$round_numerator
= 60 * 15 // 60 seconds per minute * 15 minutes equals 900 seconds
//$round_numerator = 60 * 60 or to the nearest hour
//$round_numerator = 60 * 60 * 24 or to the nearest day

// Calculate time to nearest 15 minutes!
$rounded_time = ( round ( time() / $round_numerator ) * $round_numerator );

//If it was 12:40 this would return the timestamp for 12:45;
//3:04, 3:00; etc.
?>
AT-HE (at_he at h0tm4il dot com)
05-Jun-2006 11:54
egingell:
better use gmdate() function which has no need to shift local time ;)

<?
function gmtime() {
   return
gmdate();
}
?>
egingell at sisna dot com
03-May-2006 01:00
<?

/**
 * Returns the true time in seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
 *
 * Calling date() with gmtime() as the second parameter is identical to calling
 * gmdate() with time() as the second parameter.
 **/
function gmtime() {    // Get GM offset. See manual/en/function.date.php   
  
return time() - (int) date('Z');
}

?>
info at exitorange dot com
21-Feb-2006 08:11
in order to get the timestamp of the beginning of the current day (useful for synchronising) just do this:

$time = time();
$start_time = mktime(0, 0, 0, date('m', $time),date('d', $time),date('Y', $time));
emory dot smith at gmail dot com
19-Feb-2006 04:17
heres another way to convert a mysql timestamp to a unix timestamp without using the function UNIX_TIMESTAMP in mysql:

<?php
$unix_timestamp
= strtotime($mysql_timestamp);
?>
aidan at php dot net
07-Oct-2005 05:14
* A simple function for calculating the number of seconds, minutes, etc in a timestamp is here:
http://aidan.dotgeek.org/repos/?file=Duration.php

Example:
<?php
$time
= 60*60*2 + 20*60 + 5;

// Gives 2 hours, 20 minutes, 5 seconds
echo Duration::toString($time);

?>

* For manipulating arbitrary format, or length timestamps, see the PEAR::Date class.
http://pear.php.net/package/Date/

* PHP 6 will be shipping a new inbuilt date and timestamp manipulation API. It's available on PECL here:
http://pecl.php.net/package/date_time
mayank_arya at hotmail dot com
28-May-2003 06:13
Here's one way to generate all intermediate dates (in mySQL format) between any 2 dates.
Get start and end dates from user input, you'd need to do the basic validations that :
- start and end dates are valid dates
- start date <= end date.

<?php
//start date 2001-02-23
$sm=2;
$sd=23;
$sy=2001;

//end date 2001-03-14
$em=3;
$ed=14;
$ey=2001;

//utc of start and end dates
$s=mktime(0,0,0,$sm, $sd, $sy);
$e=mktime(0,0,0,$em, $ed, $ey);

while(
$s<=$e){
print
date('Y-m-d',$s)."< br >"; //display date in  mySQL format
$s=$s+86400; //increment date by 86400 seconds(1 day)
}

Hope this helps :)

?>
paul at honeylocust dot com
13-Jun-2002 12:56
Be careful about using the database clock (say UNIX_TIMESTAMP() in MySQL) and the time() function if you're writing an application that may have the database be on a different machine than the web server.  In that situation,  applications can break because of clock skew -- use a single authority for timestamps if possible.
matt at blockdev dot net
22-Sep-2001 07:04
Lots of MySQL traffic, little PostgreSQL.  PG hasn't UNIX_TIMESTAMP()- instead, use:

extract(epoch from ____)

As in:

SELECT extract(epoch from mytimestamp) FROM mytable WHERE mycondition = true;
08-Sep-2000 12:42
To convert a MySQL timestamp to a Unix-style timestamp, use MySQL's UNIX_TIMESTAMP function.

For Example:
$result=mysql_query ("SELECT UNIX_TIMESTAMP(timestamp_column) as epoch_time FROM table");

$unix_timestamp = mysql_result ($result, 0, 0);

<strtotimeDB++>
 Last updated: Mon, 14 Nov 2005