php時間戳與字串的相互轉換

2021-05-28 04:35:39 字數 696 閱讀 2409

php date()函式的第二個引數是int型別的,如果是字串型別的,結果就會變成1970-01-01 xx:xx:xx,那麼如何將兩種型別的時間互轉呢?查了下php 的api,原來有這麼個函式,它就是strtotime()…

php**

<?php  

date_default_timezone_set(「prc」); 

$stringtime = date(「y-m-d h:i:s」,time()); 

echo

$stringtime.」

」; 

echo

strtotime($stringtime).」

」; 

echo

date(「y/m/d g:i:s a」,strtotime($stringtime)); 

?> 

<?php 

date_default_timezone_set(「prc」);

$stringtime = date(「y-m-d h:i:s」,time());

echo $stringtime.」

」;echo strtotime($stringtime).」

」;echo date(「y/m/d g:i:s a」,strtotime($stringtime));

?>

php時間戳與字串的相互轉換

php date 函式的第二個引數是int型別的,如果是字串型別的,結果就會變成1970 01 01 xx xx xx,那麼如何將兩種型別的時間互轉呢?查了下php 的api,原來有這麼個函式,它就是strtotime date default timezone set prc stringtime...

php時間戳與字串的相互轉換

date default timezone set prc 將時區設定為中國 stringtime date y m d h i s time echo stringtime.echo strtotime stringtime echo date y m d g i s a strtotime st...

hive 中時間戳與時間字串的相互轉換

時間戳是資料庫常用的存放日期的形式之一,表示從 utc 時間 1970 01 01 00 00 00 開始到現在的秒數,與常規時間格式如 2018 01 01 00 00 00 可以相互轉換,方法如下。一 unix timestamp 函式用法 1 unix timestamp 返回當前時間戳。另外...