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)
?>