-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathobjectOriented.php
More file actions
113 lines (76 loc) · 2.59 KB
/
objectOriented.php
File metadata and controls
113 lines (76 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
class DateTimeHandler extends DateTime {
private $formatter = null;
public function __construct($time, DateTimeZone $zone=null){
Locale::setDefault('tr_TR.utf-8');
$this->setFormatterInstance();
parent::__construct($time,$zone);
}
private function setFormatterInstance(){
$this->formatter = new IntlDateFormatter(
"tr-TR",
IntlDateFormatter::LONG,
IntlDateFormatter::NONE,
"Europe/Istanbul",
IntlDateFormatter::GREGORIAN,
"YYYY-MM-DD"
);
}
public function diff($now = 'NOW',$absolute=null) {
if(!($now instanceOf DateTime)) {
$now = new DateTime($now);
}
return parent::diff($now);
}
public function getAge($now = 'NOW') {
return $this->diff($now)->format('%y');
}
public function format($format){
$this->formatter->setPattern($format);
return $this->formatter->format($this);
}
}
$birthday = new DateTimeHandler('1879-03-14 23:00:00');
echo $birthday->format("dd MM YYYY EEEE");
echo '<p>Albert Einstein yaşasaydı ', $birthday->getAge(), ' yaşında olurdu.</p>';
echo '<p>Albert Einstein yaşasaydı ', $birthday->diff()->format('%y Years, %m Months, %d Days'), ' yaşında olurdu.</p>';
echo '<p>Albert Einstein, 2010-01-01 yılında yaşasaydı ', $birthday->getAge('2010-01-01'), ' yaşında olurdu.</p>';
$today = new DateTime('today');
var_dump($today);
$today -> modify('-2 days');
var_dump($today);
die();
echo $today -> format('Y-m-d') . PHP_EOL;
$today = new DateTime('today');
var_dump($today);
$today -> add(new DateInterval('P2D')) -> sub(new DateInterval('P1M'));
var_dump($today);
die();
$today -> sub(new DateInterval('P1M'));
var_dump($today);
die();
$today = new DateTime('today');
$TCFirstDay = new DateTime('1923-10-29');
$interval = $today -> diff($TCFirstDay);
var_dump($today > $TCFirstDay);
var_dump($today < $TCFirstDay);
var_dump($today == $TCFirstDay);
var_dump($interval);
echo 'Cumhuriyetin ilanından bugüne ', $interval -> format('%y'), ' yıl geçti';
die();
echo '<h3>Mevcut zaman</h3>';
$currentDateTime = new DateTime();
echo $currentDateTime -> format('d.m.Y H:i:s');
die();
echo '<h3>Dün</h3>';
$yesterday = new DateTime('yesterday');
var_dump($yesterday);
echo '<h3>İki gün sonra</h3>';
$twoDaysLater = new DateTime('+ 2 days');
var_dump($twoDaysLater);
echo '<h3>1 hafta önce</h3>';
$oneWeekEarly = new DateTime('- 1 week');
var_dump($oneWeekEarly);
echo '<h3>Özbekistan Taşkent\'te dün. </h3>';
$yesterdayInTashkent = new DateTime('yesterday', new DateTimeZone('Asia/Tashkent'));
var_dump($yesterdayInTashkent);