php符串內美國時間轉為中國時間

2022-07-03 10:50:09 字數 5474 閱讀 6843

1樓:匿名使用者

<?php

date_default_timezone_set("prc");

0';$arr=explode('timevalue=',$str);

$substr1=$arr[0];

$brr=explode(';',$arr[1]);

$substr2=date("y-m-d h:i:s",strtotime($brr[0]));

$crr=explode(';',$arr[2]);

$substr3=date("y-m-d h:i:s",strtotime($crr[0]));

$strnew=$substr1.'timevalue='.$substr2.

';'.$brr[1].'timevalue='.

$substr3.';'.$crr[1];

echo $str."

";echo $strnew;

?>

2樓:匿名使用者

$str = 'sun jan 18 01:39:21 cst 2015';

echo date('y-m-d h:i:s', strtotime($str));

不能加後面分號那部分,如:「;30.0」,暫時不清楚這部分表示什麼意思

php將字串「201409161025」轉換成日期時間格式「2014/09/16010:25」

3樓:

<?php

function getdates($string)echo getdates('201409161025');

?>

寫個很函式,直接呼叫即可。

望採納 thx

4樓:豐鴻福

$a = "201409161025";

echo substr($a, 0,4).'/'.substr($a, 4, 2).

'/'.substr($a, 6, 2).' '.

substr($a, 8, 2).':'.

substr($a, 10, 2);

這樣是最簡單易懂的。

5樓:匿名使用者

date("y/m/d h:i",strtotime("201409161025"))

php裡date("h")得到的是格林尼治時間,怎麼轉為北京時間?

6樓:跌落水的烏鴉

date_default_timezone_set('prc');

不要少了引號,prc不是常量

php 字串時間轉換問題

7樓:匿名使用者

<?php

$str='20150926085700';

echo substr($str,0,4).'-'.substr($str,4,2).

'-'.substr($str,6,2).' '.

substr($str,8,2).':'.

substr($str,10,2).':'.

substr($str,12,2);

8樓:匿名使用者

$a = substr("20150926085700",0,4);

$b = substr("20150926085700",6,2);

.....

$time = $a.'-'.$b.' ..............懂了吧

php字串轉時間

9樓:sou2n魔王

誰說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如果不能正確接收「年-月-日 時:分:秒」,輸出的應該就不是這個時間了。

10樓:豐鴻福

$a = "20140901160922";

echo substr($a, 0,4).'-'.substr($a, 4, 2).

'-'.substr($a, 6, 2).' '.

substr($a, 8, 2).':'.

substr($a, 10, 2).':'.

substr($a, 12, 2);

php怎麼將指定日期轉換為時間戳

11樓:匿名使用者

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解析器的解析時間,速度相對慢。

擴充套件資料

php建構函式和解構函式

1、在 php4 中,當函式與物件同名時,這個函式將成為該物件的建構函式,並且在 php4 中沒有解構函式的概念。

2、在 php5 中,建構函式被統一命名為 __construct,並且引入了解構函式的概念,被統一命名為 __destruct。

3、在php4中,傳遞變數給一個函式或方法,實際是把這個變數做了一次複製,也就意味著你傳給函式或方法的是這個變數的一個副本,除非你使用了引用符號「&;」 來宣告是要做一個引用,而不是一個 copy。

4、在 php5中,物件總是以引用的形式存在的,物件中的賦值操作同樣也都是一個引用操作。

參考資料

12樓:冰封月

使用strotime函式,**如下;

<?php

echo strtotime("now"), "\n";

echo strtotime("10 september 2000"), "\n";

echo strtotime("+1 day"), "\n";

echo strtotime("+1 week"), "\n";

echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";

echo strtotime("next thursday"), "\n";

echo strtotime("last monday"), "\n";

echo strtotime("20170808 23:00:01"), "\n";

13樓:

使用內建函式strtotime()在php中可以將指定日期轉換為時間戳,具體操作請參照以下步驟。

1、首先了解函式strtotime()的功能及用法。

2、然後在php的編輯器中輸入要轉化為時間戳的日期。

3、儲存之後可以在瀏覽器中預覽列印結果,目標日期的時間戳就出來了。

4、然後在php的編輯器中輸入要轉化為時間戳的標準時間格式的日期。

5、儲存之後可以在瀏覽器中預覽列印結果,標準時間格式日期的時間戳就出來了。完成以上設定後,即可在在php中將指定日期轉換為時間戳。

14樓:當哆啦離開a夢

php 中的 strtotime() 函式可以實現。

strtotime() 函式將任何英文文字的日期時間描述解析為 unix 時間戳。

strtotime(time,now),其中,time 規定要解析的時間字串,now 用來計算返回值的時間戳。如果省略該引數,則使用當前時間。

成功則返回時間戳,否則返回 false。在 php 5.1.0 之前本函式在失敗時返回 -1。

15樓:請叫我王老大

在mysql中完成

這種方式在mysql查詢語句中轉換,優點是不佔用php解析器的解析時間,速度快,缺點是隻能用在資料庫查詢中,有侷限性。

1. unix時間戳轉換為日期用函式: from_unixtime()

一般形式:select from_unixtime(1156219870);

2. 日期轉換為unix時間戳用函式: unix_timestamp()

一般形式:select unix_timestamp('2006-11-04 12:23:00′);

舉例:mysql查詢當天的記錄數:

$sql=」select * from message where date_format(from_unixtime(chattime),'%y-%m-%d') = date_format(now(),'%y-%m-%d') order by id desc」;

當然大家也可以選擇在php中進行轉換,下面說說在php中轉換。

16樓:匿名使用者

$date = "2012-2-3 3:04:33";

echo strtotime($date);

17樓:小可

使用時間轉行函式strtotime() <?phpecho strtotime('2012-11-15 22:22:22');?>

18樓:匿名使用者

php教程 php常用功能模組 時間戳 1 什麼是時間戳 學習猿地

php獲得美國時間

19樓:

可以考慮用 pear 的 date 包

安裝:# pear install date例項:<?php

include ("date.php");

// 初始化日期物件

$d = new date("2010-04-06 10:36:27");

// 設定本地時區

$d->settzbyid("prc");

foreach(array('mit', 'hst', 'ast') as $zoneid)

20樓:平依秋

date_default_timezone_set(et); 美國東部 標準時間

一、東部時區——eastern time(et)二、中部時區——central time(ct)三、山地時區——mountain time(mt)四、太平洋時區——central time(ct)

pascal 符串的處理,PASCAL 字串的處理

好啊,我是oier哦,這個顯然很簡單。const fuhao kuohao varst,s1 string function ji ch char integer begin case ch of ji 1 ji 1 ji 2 ji 2 ji 3 end end function geti st s...

c符串擷取,c 字串擷取

沒理解你的具體意思,不過擷取字串可以用substring方法。先indexof查詢到死的部分的位置再擷取 string str e tws tws ui print 2013122423 picture picture string str1 str.substring 0,str.indexof ...

php中通過字串建立陣列

先要把字串處理一下,成為php定義陣列的形式,再用eval執行 str array 15 array id 2304 fromtype item 16 array id 2313 fromtype item 17 array id 4265 fromtype item str preg replac...