A. 新手php时间戳的问题如何获取每天凌晨的时间戳
方法有很多
第一种:
$today_zero=strtotime('today');//说明:strtotime支持英语
第二种:
$today_zero=strtotime(date('Y-m-d',time()));//说明:先获取现在的时间所在的日期格式2013-09-01,然后把它转换为时间戳
其中,第二种还可以简单点写:$today_zero=strtotime(date('Y-m-d'));
也就是说,不填当前时间,也是可以的
B. php 字符串内美国时间转为中国时间
//原始字符串
$pre='count=2&dpxid=DP_508368&timevalue=SunJan1801:39:21CST2015;30.0&dpxid=DP_981391&timevalue=SunJan1801:39:20CST2015;24.0';
//定义回调函数
functionu_ctime($matches){
$utime=strtotime($matches[1]);//转换为时间戳
$ctime=$utime+13*60*60;//西五区变为东八区
$ct_str=date("DMds:i:hTY",$ctime);//转换为字符串
return'value='.$ct_str.';';
}
$str=preg_replace_callback('|value=([w:]*);|','u_ctime',$pre);
C. php时间格式怎么转换
php日期格式转换总结:
<?php
//将当前时间转换成yyyy-mm-dd格式串,再转换成日期格式,绕了一圈哈
echo strtotime(date('Y-m-d',time()).' 00:00:00');
//将GNU 日期输入格式的字符转换成时间
echo strtotime('now');
//标准的字符串转换成时间
$t = '2012-9-10 15:18:06';
$time = strtotime($t);
//将时间转换成日期字符yyyymmdd,再转换成整型格式
$d = intval(date('Ymd',$time));
echo '付款时间:'.$d;
<?php
header("Content-type: text/html; charset=utf-8");
$txDate = '2016-06-16';
$dateTime1 = strtotime($txDate); //int 1466028000 将英文文本日期时间解析为 Unix 时间戳:
$dateTime2= date("Y-m-d H:i:s",$dateTime1); //string '2016-06-16 00:00:00'
(length=19) Date() 函数把时间戳格式化为更易读的日期和时间。
//拼接今日最后时间2016-06-16 23:59:59
$dateTime= date("Y-m-d H:i:s",strtotime(date("Y-m-d",strtotime($dateTime2))."+ 23 hours 59 minutes 59 seconds ")); //string '2016-06-16 23:59:59' (length=19)
$sql = select * form `vvt_user` where userid = 100 AND date_time >= $dateTime2 AND date_time <= $dateTime;?>
D. php中时间戳转换
1. UNIX时间戳转换为日期用函数: date()
一般形式:date('Y-m-d H:i:s', 1156219870);
2. 日期转换为UNIX时间戳用函数:strtotime()
一般形式:strtotime('2010-03-24 08:15:42');
3.转换为年月日:
代码如下:date("Y-m-d",strtotime($vo[shijian]));
E. php字符串转时间
谁说strtotime不接收“年-月-日 时:分:秒”?
<?php
$time = strtotime("2010-09-08 07:06:05");
echo date("Y-m-d H:i:s",$time);
?>
输出 2010-09-08 07:06:05
如果不能正确接收“年-月-日 时:分:秒”,输出的应该就不是这个时间了。
F. php怎么将日期格式变成时间戳,
strtotime把任何格式的日期转换为时间戳。
格式:int
strtotime
(
string
time
[,
int
now]
);
本函数预期接受一个包含美国英语日期格式的字符串并尝试将其解析为
Unix
时间戳(自
January
1
1970
00:00:00
GMT
起的秒数),其值相对于
now
参数给出的时间,如果没有提供此参数则用系统当前时间。
本函数将使用
TZ
环境变量(如果有的话)来计算时间戳。自
PHP
5.1.0
起有更容易的方法来定义时区用于所有的日期/时间函数。此过程在
date_default_timezone_get()
函数页面中有说明。
注:
如果给定的年份是两位数字的格式,则其值
0-69
表示
2000-2069,70-100
表示
1970-2000。
G. php怎么将指定日期转换为时间戳
date('Y-m-d H:i:s', 1156219870);
1、 UNIX时间戳转换为日期用函数: date()
一般形式:date('Y-m-d H:i:s', 1156219870);
2、日期转换为UNIX时间戳用函数:strtotime()
一般形式:strtotime('2010-03-24 08:15:42');
3、这种方式在PHP程序中完成转换,优点是无论是不是数据库中查询获得的数据都能转换,转换范围不受限制,缺点是占用PHP解析器的解析时间,速度相对慢。
(7)php字符串转换时间戳扩展阅读
PHP构造函数和析构函数
1、在 PHP4 中,当函数与对象同名时,这个函数将成为该对象的构造函数,并且在 PHP4 中没有析构函数的概念。
2、在 PHP5 中,构造函数被统一命名为 __construct,并且引入了析构函数的概念,被统一命名为 __destruct。
3、在PHP4中,传递变量给一个函数或方法,实际是把这个变量做了一次复制,也就意味着你传给函数或方法的是这个变量的一个副本,除非你使用了引用符号“&;” 来声明是要做一个引用,而不是一个 Copy。
4、在 PHP5中,对象总是以引用的形式存在的,对象中的赋值操作同样也都是一个引用操作。
参考资料
网络-php
H. php怎么将指定期时间转为时间戳(时间戳精确到毫秒)
php并没有直接支持毫秒的日期时间函数,所以要想得到毫秒级的时间戳,就要把秒级的时间戳*1000。
需要注意的是,由于毫秒级的时间戳已经远远超过整数的大小范围,所以要用浮点数(且精度不能低于13位)来储存。
另外,要想把毫秒级的时间戳转为时间,务必先/1000再转换,否则错误,因为php并不认识所谓的毫秒级时间戳!
不过,虽然无法获得指定时间的毫秒级时间戳,但要想获得当前时间的毫秒数,却是有办法的:
echo microtime(true)*1000;