Değişik Stillerde Türkçe Tarih Gösterimi

PHP
75 lines
<?php
class tarih_tr{
function gun_tr($gun){
switch($gun){
case 0 : $gun = "Pazar";
break;
case 1 : $gun = "Pazartesi";
break;
case 2 : $gun = "Salı";
break;
case 3 : $gun = "Çarşamba";
break;
case 4 : $gun = "Perşembe";
break;
case 5 : $gun = "Cuma";
break;
case 6 : $gun = "Cumartesi";
break;
}
return $gun;
}
function ay_tr($ay){
switch($ay){
case 1 : $ay = "Ocak";
break;
case 2 : $ay = "Şubat";
break;
case 3 : $ay = "Mart";
break;
case 4 : $ay = "Nisan";
break;
case 5 : $ay = "Mayıs";
break;
case 6 : $ay = "Haziran";
break;
case 7 : $ay = "Temmuz";
break;
case 8 : $ay = "Ağustos";
break;
case 9 : $ay = "Eylül";
break;
case 10 : $ay = "Ekim";
break;
case 11 : $ay = "Kasım";
break;
case 12 : $ay = "Aralık";
break;
}
return $ay;
}
function hazirla($stil){
if(empty($stil) or $stil>4 or $stil<1){
$stil = 4;
}
if($stil==1){
$veri = date("d")."/".date("m")."/".date("y");
}elseif($stil==2){
$veri = date("d")."/".date("m")."/".date("Y");
}elseif($stil==3){
$veri = date("d")."/".date("m")."/".date("Y")." ".$this->gun_tr(date("w"));
}elseif($stil==4){
$veri = date("d")." ".$this->ay_tr(date("n"))." ".date("Y")." ".$this->gun_tr(date("w"));
}
return $veri;
}
}
$dt = new tarih_tr;
echo $dt->hazirla(1);
echo "<br>";
echo $dt->hazirla(2);
echo "<br>";
echo $dt->hazirla(3);
echo "<br>";
echo $dt->hazirla(4);
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
4 lines
30/05/18
30/05/2018
30/05/2018 Çarşamba
30 Mayıs 2018 Çarşamba
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Tarih ve Saat Dönüştürme Sınıfı

PHP
31 lines
<?php
date_default_timezone_set('Europe/Istanbul');
class TarihYonet {
public $girilen;
public $damga;
public $tarih;
public $zaman;#YYYY-MM-DD HH:MM:SS
function __construct($girilen) {
$this->girilen = trim($girilen);
if (preg_match("/^\d{4}-\d{2}-\d{2}$/", $this->girilen)) {
$tarihDizi = explode('-', $this->girilen);
$this->tarih = $this->girilen;
$this->damga = mktime(0, 1, 1, $tarihDizi[1], $tarihDizi[2], $tarihDizi[0]);
$this->zaman = date('Y-m-d H:i:s', $this->damga);
} else if (preg_match("/^\d{4}-\d{2}-\d{2} [0-2][0-3]:[0-5][0-9]:[0-5][0-9]$/", $this->girilen)) {
$parcala = explode(' ', $this->girilen);
$tarihDizi = explode('-', $parcala[0]);
$this->zaman = $this->girilen;
$this->damga = mktime(0, 1, 1, $tarihDizi[1], $tarihDizi[2], $tarihDizi[0]);
$this->tarih = date('Y-m-d', $this->damga);
} else {
$this->damga = $this->girilen;
$this->tarih = date('Y-m-d', $this->girilen);
$this->zaman = date('Y-m-d H:i:s', $this->girilen);
}
}
}
$ornek = new TarihYonet(time());
print_r($ornek);
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

TarihYonet Object
(
    [girilen] => 1526461072
    [damga] => 1526461072
    [tarih] => 2018-05-16
    [zaman] => 2018-05-16 11:57:52
)