php date



date()

格式化本地一个时间/日期

string date(string $format[, int $timestamp])

返回按照format给定格式字符串而产生的字符串,如果timestamp没有给出,默认使用当前本地时间即time()


date_default_timezone_set()

设定所有日期时间函数在当前脚本中所使用的默认时区

bool date_default_timezone_set( string $timezone)

如果参数timezone无效返回false否则返回true

中国时区设定:PRC

<?php
    date_default_timezone_set('PRC');
    echo date('Y-m-d H:i:s');
?>

date_default_timezone_get()

取得当前脚本默认时区

getdate()

取得一个日期时间信息

array getdate([int $timestamp])

根据timestamp返回一个日期时间的数组信息,如果timestamp没有提供则使用本地当前时间time()

<?php
    print_R(getdate());
?>
输出:

Array ( [seconds] => 9 [minutes] => 59 [hours] => 3 [mday] => 28 [wday] => 3 [mon] => 11 [year] => 2012 [yday] => 332 [weekday] => Wednesday [month] => November [0] => 1354075149 )


time()

返回当前时间戳


mktime()

取得一个日期的时间戳

int mktime(int $hour[, int $minute[, int $second[, int $month[, int $day[, int $year]]]])

根据给出的时间返回对应时间戳,出错时返回false

参数可以自右想左省略,省略的参数用本地的时间代替。


strtotime()

将任何格式的英文格式日期转换为unix时间戳

int strtotime(string $time[, int $now])

 本函数预期接受一个包含美国英语日期格式的字符串并尝试将其解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数),其值相对于 now 参数给出的时间,如果没有提供此参数则用系统当前时间。

<?php
    echo strtotime('now');//1354004823
    echo strtotime('+1 second');//1354004824
?>







  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值