mysql怎么获取时间戳的函数unix_timestamp?我们收集了网络上流行的各种关于获取unix_timestamp的方法总结。
create trigger cus_info_tbl_tr after insert on cus_info_tbl
for each row
insert into summary_tbl ( `school_id`, `province_id`, `city_id`, `year`, `month`, `day`, `hour`, `minute`, `first_time`, `intdate` ) values
( new.school_id,
new.province_id,
new.city_id,
year( new.date_call ),
month( new.date_call ),
dayofmonth( new.date_call ),
hour( new.date_call ),
minute( new.date_call ),
new.first_time,
unix_timestamp( new.date_call )+28800
);
看到了吧,在这个时间戳后面再加上8个小时的秒数就搞定了,呵呵。
不过我在google的时候注意到有很多兄弟都反应unix_timestamp和php中的mktime得到的值是一样的,但是我这里却出现了问题,到现在也没有能够找到原因。
代码如下 复制代码
unix_timestamp(), unix_timestamp(date)
若无参数调用,则返回一个unix timestamp ('1970-01-01 00:00:00' gmt 之后的秒数) 作为无符号整数。若用date 来调用unix_timestamp(),它会将参数值以'1970-01-01 00:00:00' gmt后的秒数的形式返回。date 可以是一个date 字符串、一个 datetime字符串、一个 timestamp或一个当地时间的yymmdd 或yyymmdd格式的数字。
查询
mysql中unix_timestamp()函数的应用比较
应用:
代码如下 复制代码
select(
unix_timestamp(endtime)-unix_timestamp(startime)
)/31536000year,id,name
fromtestime
limit0,30
这里我们可以使用
from_unixtime(unix_timestamp), from_unixtime(unix_timestamp,format) 来格式化一个unix_timestamp()时间戳,它将返回'yyyy-mm-dd hh:mm:ss'或yyyymmddhhmmss 格式值的 unix_timestamp参数表示,具体格式取决于该函数是否用在字符串中或是数字语境中。
若format 已经给出,则结果的格式是根据format 字符串而定。 format 可以包含同date_format() 函数输入项列表中相同的说明符。
代码如下 复制代码
mysql> select from_unixtime(875996580);
-> '1997-10-04 22:23:00'
mysql> select from_unixtime(875996580) + 0;
-> 19971004222300
mysql> select from_unixtime(unix_timestamp(),
-> '%y %d %m %h:%i:%s %x');
-> '2003 6th august 06:22:58 2003'
php中:time()
time -- 返回当前的 unix 时间戳
strtotime() 也可以转换unix 时间戳