php土耳其月NOW()函数

时间:2014-08-27 23:11:54

标签: php

我有一个关于php日期时间的问题。

我的数据库表中有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

2 个答案:

答案 0 :(得分:3)

快速执行此操作的方法是使用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

答案 1 :(得分: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日

不确定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);
?>