2014-08-27 65 views
-1

我有一個問題的PHP日期時間。PHP土耳其語月NOW()函數

我在我的數據庫表中有join_time。當我創建新的帖子時,它張貼如下:2014-08-28 01:02:57

我正在使用NOW()函數。

我的問題是怎麼讓這個日期與<?php echo $join_time ;?>這樣的:

28 August 201428 Ağustos 2014

所以我想借此2014-08-28 01:02:57並把它變成28 Ağustos 2014

+1

[strftime()](http://www.php.net/manual/en/function.strftime.php) – 2014-08-27 23:12:45

+0

@MarkBaker如何使用in echo進行編輯? – Jilet 2014-08-27 23:13:48

+0

你想'NOW()'輸入數據庫中的日期時間,比如'28Ağustos2014'?或者你想把'2014-08-28 01:02:57'變成'28Ağustos2014'? – Alex 2014-08-27 23:16:33

回答

0

這裏亞去:

<?php 

setlocale(LC_TIME, 'tr_TR'); // set locale 

$str = '2014-08-28 01:02:57'; // your timestamp 

$justDate = substr($str, 0, strpos($str, ' ')); // get only date, trim to first space 

$date = new DateTime($justDate); 
$result = $date->format('d F Y'); // format date 

echo $result; 

?> 

匝數2014-08-28 01:02:57從2014年8月28日到2015年

不能確定的setlocale工作,它應該,但如果沒有,你可以做一些陣列的工作與英語土耳其月份名稱

使用數組的表:

<?php 

$langArr = array('8' => 'Ağustos'); // just complete this 

$str = '2014-08-28 01:02:57'; // your timestamp 

$justDate = substr($str, 0, strpos($str, ' ')); // get only date 

$date = new DateTime($justDate); 
// you dont need to format it in an array, i just did since its easier than adding spaces 
$result[] = $date->format('d'); // day 
$result[] = $langArr[$date->format('n')]; // month numeric for array 
$result[] = $date->format('Y'); // year 

echo implode(' ', $result); 
?> 
+0

*「,但如果不是,你可以做一些數組工作」* - 這是我的回答站在幫助OP。 Downvoted也是如此。我可能最終刪除它。 – 2014-08-27 23:49:27

+0

是的,我確認setlocale似乎只能從手冊「strftime()'用於使用strftime()進行日期和時間格式化的LC_TIME」...因此,數組工作可能需要完成。 derps答案應該是最好的壽,但它不適合我。 – Alex 2014-08-27 23:52:34

+0

*嗯* ...有趣。我看了一下答案。看起來有希望我會刪除我的答案。然而,今天晚上真的很奇怪。我早些時候提出了一個答案,得到了3分讚賞。點沒有註冊。我得到了我的答案downvote,並註冊了大聲笑 - 噢,我標記了我的兩個答案,並讓Stack看看它。 – 2014-08-27 23:54:24

2

一個快速的方法要做到這一點是使用strtotime()來創建你有日期戳,然後用strftime()格式化:

echo strftime('%e %B %Y', strtotime('2014-08-28 01:02:57')); 

這將輸出28 August 201428 Ağustos 2014,具體取決於當前的語言環境。有關更多信息,請參閱:setlocale()


注:不支持Windows上的%e修飾符strftime。在那裏可以使用修飾符%#d

+0

輸出空白? – Alex 2014-08-27 23:50:32

+0

很酷。更清潔。這應該是被接受的。 – Alex 2014-08-27 23:59:01