如何用土耳其语显示PHP日期?

时间:2013-02-14 06:19:27

标签: php date time localization

如何以土耳其语显示日期? 我正在尝试使用代码但它根本不打印任何内容。

setlocale(LC_ALL, 'tr_TR.UTF-8');
echo strftime("%e %B %Y %A", time());

6 个答案:

答案 0 :(得分:8)

虽然我不懂土耳其语但是打印输出

  14 Şubat 2013 Perşembe

所以你的代码很好。 希望你不要错过php标签。 :/

答案 1 :(得分:1)

<?php
            setlocale(LC_ALL, 'tr_TR.UTF-8');
            echo strftime("%e %B %Y %A", time());
          ?>

打印出来:30 Ekim 2015 Cuma

代码工作正常。

答案 2 :(得分:0)

在代码之前添加它。

setlocale (LC_ALL, 'tr_TR.UTF-8', 'tr_TR', 'tr', 'turkish');

答案 3 :(得分:0)

   public function getTurkishDate(){
       $locale = 'tr_TR'; // a canonicalized locale
       $format = 'dd-MMMM-YYYY'; // ISO format codes, not the typical date ones
       $dt = new DateTime(); // a DateTime object
       $df = new IntlDateFormatter(
           $locale, // string locale
           IntlDateFormatter::NONE, // int date type
           IntlDateFormatter::NONE, // int time type
           'UTC', // string timezone
           IntlDateFormatter::GREGORIAN, // int cal type
           $format // string pattern
       );
       return $df->format($dt); //string 07-Ağustos-2018
    } 

OR

    public function getTurkishDate(){
        $locale = 'tr_TR'; // a canonicalized locale
        $format = 'dd-MMMM-YYYY-EEEE'; // ISO format codes, not the typical date ones
        $dt = new DateTime(); // a DateTime object
        $df = new IntlDateFormatter(
            $locale, // string locale
            IntlDateFormatter::NONE, // int date type
            IntlDateFormatter::NONE, // int time type
            'UTC', // string timezone
            IntlDateFormatter::GREGORIAN, // int cal type
            $format // string pattern);
        return $df->format($dt); //string 07-Ağustos-2018-Salı
    } 

OR

    public function getTurkishDate(){
        $locale = 'tr_TR'; // a canonicalized locale
        $format = 'dd-MMMM-YYYY-ee'; // ISO format codes, not the typical date ones
        $dt = new DateTime(); // a DateTime object
        $df = new IntlDateFormatter(
            $locale, // string locale
            IntlDateFormatter::NONE, // int date type
            IntlDateFormatter::NONE, // int time type
            'UTC', // string timezone
            IntlDateFormatter::GREGORIAN, // int cal type
            $format // string pattern);
        return $df->format($dt); //string 07-Ağustos-2018-02
    } 

答案 4 :(得分:0)

您可以通过以下方式获取当前日期和时间:

<?php
date_default_timezone_set("Europe/Istanbul");
//echo "The time is " . date("H:i") . "<br>";
//echo "Today is " . date("Y-m-d") . "<br>";
//echo "Today is " . date("l");
$now_time = date("H:i");
$now_date = date("Y-m-d");
?>

答案 5 :(得分:0)

“ F”的hp日期,它给出了英文名称的月份,可以翻译成土耳其语

date("d F")

您可以使用此功能

   function convertMonthToTurkishCharacter($date){
    $aylar = array(
        'January'    =>    'Ocak',
        'February'    =>    'Şubat',
        'March'        =>    'Mart',
        'April'        =>    'Nisan',
        'May'        =>    'Mayıs',
        'June'        =>    'Haziran',
        'July'        =>    'Temmuz',
        'August'    =>    'Ağustos',
        'September'    =>    'Eylül',
        'October'    =>    'Ekim',
        'November'    =>    'Kasım',
        'December'    =>    'Aralık',
        'Monday'    =>    'Pazartesi',
        'Tuesday'    =>    'Salı',
        'Wednesday'    =>    'Çarşamba',
        'Thursday'    =>    'Perşembe',
        'Friday'    =>    'Cuma',
        'Saturday'    =>    'Cumartesi',
        'Sunday'    =>    'Pazar',
        'Jan' => 'Oca',
        'Feb' => 'Şub',
        'Mar' => 'Mar',
        'Apr' => 'Nis',
        'May' => 'May',
        'Jun' => 'Haz',
        'Jul' => 'Tem',
        'Aug' => 'Ağu',
        'Sep' => 'Eyl',
        'Oct' => 'Eki',
        'Nov' => 'Kas',
        'Dec' => 'Ara'

    );
    return  strtr($date, $aylar);
}