繁体   English   中英

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

[英]How to display PHP date in Turkish?

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

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

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

  14 Şubat 2013 Perşembe

所以你的代码没问题。 希望你不会错过 php 标签。 :/

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

打印出来:30 Ekim 2015 Cuma

代码工作正常。

在代码之前添加它。

setlocale (LC_ALL, 'tr_TR.UTF-8', 'tr_TR', 'tr', 'turkish');
   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
    } 

要么

    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ı
    } 

要么

    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
    } 

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

<?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");
?>

“F”的 PHP 日期,给出英文名称的月份以翻译成土耳其语给定示例

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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM