2014-08-27 66 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