计算差额是可以的,定时不可以。
计算时差有两种方法,可以用PHP的函数,也可以用数据库的函数。PHP中函数int time ( void )返回自从 Unix 纪元(格林威治时间 1970 年 1 月 1 日 00:00:00)到当前时间的秒数。自 PHP 5.1 起在 $_SERVER['REQUEST_TIME'] 中保存了发起该请求时刻的时间戳。 计算差之前,需要利用函数mktime把参数转化为整数,函数格式为:int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] ),功能是根据给出的参数返回 Unix 时间戳。时间戳是一个长整数,包含了从 Unix 纪元(January 1 1970 00:00:00 GMT)到给定时间的秒数。 参数可以从右向左省略,任何省略的参数会被设置成本地日期和时间的当前值。
如果你的日期是来源于数据库的字段,那么查询语句里面可以直接查询数据库服务器的当前日期,甚至把时间差一起计算出来,PHP无须编写程序,直接象使用普通字段变量一样使用。
gmstrftime('%H:%M:%S',800);
显示格式如下:
00:03:27
Definition and Usage
The gmstrftime() function formats a GMT/UTC time or date according to locale settings.
Syntax
gmstrftime(format,timestamp)
Parameter
Description
format
Required. Specifies how to return the result:
%a - abbreviated weekday name
%A - full weekday name
%b - abbreviated month name
%B - full month name
%c - preferred date and time representation
%C - century number (the year divided by 100, range 00 to 99)
%d - day of the month (01 to 31)
%D - same as %m/%d/%y
%e - day of the month (1 to 31)
%g - like %G, but without the century
%G - 4-digit year corresponding to the ISO week number (see %V).
%h - same as %b
%H - hour, using a 24-hour clock (00 to 23)
%I - hour, using a 12-hour clock (01 to 12)
%j - day of the year (001 to 366)
%m - month (01 to 12)
%M - minute
%n - newline character
%p - either am or pm according to the given time value
%r - time in a.m. and p.m. notation
%R - time in 24 hour notation
%S - second
%t - tab character
%T - current time, equal to %H:%M:%S
%u - weekday as a number (1 to 7), Monday=1. Warning: In Sun Solaris Sunday=1
%U - week number of the current year, starting with the first Sunday as the first day of the first week
%V - The ISO 8601 week number of the current year (01 to 53), where
week 1 is the first week that has at least 4 days in the current year,
and with Monday as the first day of the week
%W - week number of the current year, starting with the first Monday as the first day of the first week
%w - day of the week as a decimal, Sunday=0
%x - preferred date representation without the time
%X - preferred time representation without the date
%y - year without a century (range 00 to 99)
%Y - year including the century
%Z or %z - time zone or name or abbreviation
%% - a literal % character
timestamp
Optional. Specifies the date or time to be formatted. If no timestamp is specified, it uses the current GMT time.
这个还是自定义一个函数比较好,给你写个简单的
function dataformat($num) {
$hour = floor($num/3600);
$minute = floor(($num-3600*$hour)/60);
$second = floor((($num-3600*$hour)-60*$minute)%60);
echo $hour.':'.$minute.':'.$second;
}