1. php 怎么将时间戳转化为日期格式
oracle中,日期转换函数有很多,常用命令如下:
to_char()命令将时间戳转换为用户规定的日期格式,如:
select
to_char(sysdate,'yyyy-mm-dd
hh24:mi:ss')
from
al;
语法:to_char(x
[,format])
说明:将x按format格式转换成字符串。x可以是日期或者数字或时间戳,format是一个规定了x采用何种格式转换的格式字符串
to_date()命令可以将一个日期格式的字符串转换成date类型数据,如:
select
to_date('2014-05-07
13:23:44','yyyy-mm-dd
hh24:mi:ss')
from
al;
语法:to_date(c
[,format])
说明:将符合format指定的特定日期格式的字符串c转换成date类型的数据
to_timestamp()函数可以将一个时间格式的字符串转换成时间戳
select
to_timestamp('2014-06-20
12:11:11','yyyy-mm-dd
hh24:mi:ss')
from
al;
语法:to_timestamp(c
[,format])
说明:将字符串c转换为一个时间戳数据类型
---to_char()命令可以将时间戳转换成字符串:
select
to_char(
to_timestamp('2014-06-20
12:11:11','yyyy-mm-dd
hh24:mi:ss'),'yyyy-mm-dd
hh24:mi:ss')
from
al;
当需要进行两个日期的比较时,不需要比较时间,可采用trunc()命令来截取日期
sql>
select
to_char(
trunc(sysdate),
'yyyy-mm-dd
hh24:mi:ss')
from
al;
sql>
select
to_char(
sysdate,
'yyyy-mm-dd
hh24:mi:ss')
from
al;
比较两句的运行结果,可以看到差别。
2. 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;?>
3. php时间戳转为日期
$t=1551456000000;
echodate("Y年m月d日",$t);
4. 怎样在thinkphp 查询语句中将时间戳格式转化为年月日格式,然后再作为where条件查询
使用where方法
where方法支持时间比较,例如:
//
大于某个时间
where('create_time','>
time','2016-1-1');
//
小于某个时间
where('create_time','<=
time','2016-1-1');
//
时间区间查询
where('create_time','between
time',['2015-1-1','2016-1-1']);
第三个参数可以传入任何有效的时间表达式,会自动识别你的时间字段类型,支持的时间类型包括timestamps、datetime、date和int。
使用whereTime方法
whereTime方法提供了日期和时间字段的快捷查询,示例如下:
//
大于某个时间
db('user')
->whereTime('birthday',
'>=',
'1970-10-1')
->select();
//
小于某个时间
db('user')
->whereTime('birthday',
'<',
'2000-10-1')
->select();
//
时间区间查询
db('user')
->whereTime('birthday',
'between',
['1970-10-1',
'2000-10-1'])
->select();
//
不在某个时间区间
db('user')
->whereTime('birthday',
'not
between',
['1970-10-1',
'2000-10-1'])
->select();
时间表达式
还提供了更方便的时间表达式查询,例如:
//
获取今天的博客
db('blog')
->whereTime('create_time',
'today')
->select();
//
获取昨天的博客
db('blog')
->whereTime('create_time',
'yesterday')
->select();
//
获取本周的博客
db('blog')
->whereTime('create_time',
'week')
->select();
//
获取上周的博客
db('blog')
->whereTime('create_time',
'last
week')
->select();
//
获取本月的博客
db('blog')
->whereTime('create_time',
'month')
->select();
//
获取上月的博客
db('blog')
->whereTime('create_time',
'last
month')
->select();
//
获取今年的博客
db('blog')
->whereTime('create_time',
'year')
->select();
//
获取去年的博客
db('blog')
->whereTime('create_time',
'last
year')
->select();
如果查询当天、本周、本月和今年的时间,还可以简化为:
//
获取今天的博客
db('blog')
->whereTime('create_time',
'd')
->select();
//
获取本周的博客
db('blog')
->whereTime('create_time',
'w')
->select();
//
获取本月的博客
db('blog')
->whereTime('create_time',
'm')
->select();
//
获取今年的博客
db('blog')
->whereTime('create_time',
'y')
->select();
V5.0.5+版本开始,还可以使用下面的方式进行时间查询
//
查询两个小时内的博客
db('blog')
->whereTime('create_time','-2
hours')
->select();
这些在开发手册中都可以找到的。希望可以帮到你。
5. php怎么样把时间戳换成日期
php把时间戳换成日期,用到的工具,notepad++,步骤如下:
php代码部分:
<?php
$t=time();
echo"今天的日期时间戳是:".$t."<br/>";
echo"把时间戳转换成日期:".date("Y-m-dH:i:s",$t);
?>
说明:先获取当前日期的时间戳,然后通过data函数将时间戳转换成日期,$t可以是任意的时间戳。
运行以后的效果图:
注意事项:代码必须在php环境下运行。
6. php 怎样把时间戳 转化为日期
PHP 中的 strtotime() 函数可以实现 strtotime() 函数将任何英文文本的日期时间描述解析为 Unix 时间戳。 strtotime(time,now) time 规定要解析的时间字符串。 now 用来计算返回值的时间戳。如果省略该参数,则使用当前时间。
7. 关于PHP 时间戳转换年月日问题。
<?PHP
/*
*==============================
*此方法由mantye提供
*http://my.oschina.net/u/223350
*@date2014-07-22
*==============================
*@description取得两个时间戳相差的年龄
*@before较小的时间戳
*@after较大的时间戳
*@returnstr返回相差年龄y岁m月d天
**/
$after=1529380306;
$before=time();
functiondatediffage($before,$after){
if($before>$after){
$b=getdate($after);
$a=getdate($before);
}else{
$b=getdate($before);
$a=getdate($after);
}
$n=array(1=>31,2=>28,3=>31,4=>30,5=>31,6=>30,7=>31,8=>31,9=>30,10=>31,11=>30,12=>31);
$y=$m=$d=0;
if($a['mday']>=$b['mday']){//天相减为正
if($a['mon']>=$b['mon']){//月相减为正
$y=$a['year']-$b['year'];$m=$a['mon']-$b['mon'];
}else{//月相减为负,借年
$y=$a['year']-$b['year']-1;$m=$a['mon']-$b['mon']+12;
}
$d=$a['mday']-$b['mday'];
}else{//天相减为负,借月
if($a['mon']==1){//1月,借年
$y=$a['year']-$b['year']-1;$m=$a['mon']-$b['mon']+12;$d=$a['mday']-$b['mday']+$n[12];
}else{
if($a['mon']==3){//3月,判断闰年取得2月天数
$d=$a['mday']-$b['mday']+($a['year']%4==0?29:28);
}else{
$d=$a['mday']-$b['mday']+$n[$a['mon']-1];
}
if($a['mon']>=$b['mon']+1){//借月后,月相减为正
$y=$a['year']-$b['year'];$m=$a['mon']-$b['mon']-1;
}else{//借月后,月相减为负,借年
$y=$a['year']-$b['year']-1;$m=$a['mon']-$b['mon']+12-1;
}
}
}
return($y==0?'':$y.'年').($m==0?'':$m.'个月').($d==0?'':$d.'天');
}
echodatediffage($before,$after)
?>