3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class DateTimeExtended extends DateTime { public function __get($name) { switch ($name) { case 'year': return (int)$this->format('Y'); case 'month': return (int)$this->format('n'); case 'day': return (int)$this->format('j'); case 'hour': return (int)$this->format('G'); case 'minute': return (int)$this->format('i'); case 'second': return (int)$this->format('s'); case 'dayOfWeek': return (int)$this->format('w'); case 'dayOfYear': return (int)$this->format('z'); case 'weekOfYear': return (int)$this->format('W'); case 'daysInMonth': return (int)$this->format('t'); case 'timestamp': return (int)$this->format('U'); default: throw new InvalidArgumentException(sprintf('Unknown property "%s".', $name)); } } public static function createFromFormat($format, $time, $tz = null) { if ($tz) { $date = parent::createFromFormat($format, $time, $tz); } else { $date = parent::createFromFormat($format, $time); } $errors = static::getLastErrors(); if ($errors['warning_count'] !== 0 || $errors['error_count'] !== 0) { throw new InvalidArgumentException(sprintf('Unable to parse date "%s" by pattern "%s".', $time, $format)); } if (!$date instanceof self) { return new static($date->format('Y-m-d H:i:s'), $date->getTimeZone()); } return $date; } public function format($format) { $format = preg_replace_callback('/(?:f|[Мм]есяца?|[Дд]еньнед(?:ели)?)/u', array($this, 'replaceFormatCallback'), $format); return parent::format($format); } public function replaceFormatCallback(array $matches) { switch ($matches[0]) { case 'f': return mb_strtolower(en_get_month_name($this->month)); case 'Месяц': return ru_get_month_name($this->month); case 'Месяца': return ru_get_month_name($this->month, 2); case 'месяц': return mb_strtolower(ru_get_month_name($this->month)); case 'месяца': return mb_strtolower(ru_get_month_name($this->month, 2)); case 'Деньнедели': return ru_get_weekday_name($this->dayOfWeek); case 'Деньнед': return ru_get_weekday_name($this->dayOfWeek, true); case 'деньнедели': return mb_strtolower(ru_get_weekday_name($this->dayOfWeek)); case 'деньнед': return mb_strtolower(ru_get_weekday_name($this->dayOfWeek, true)); } return $matches[0]; } public static function convert($from, $to, $value) { return static::createFromFormat($from, $value)->format($to); } public static function check($format, $value) { try { static::createFromFormat($format, $value); } catch (InvalidArgumentException $e) { return false; } return true; } } $t = microtime(true); for ($i = 0; $i < 1000; $i++) { DateTimeExtended::convert('Y-m-d', 'd.m.Y H:i:s', '2000-01-01'); } echo microtime(true) - $t;
Output for 5.5.20, 7.1.0
0.011015892028809
Output for 7.0.14
0.010655879974365
Output for 7.0.10
0.0061831474304199
Output for 7.0.9
0.0073230266571045
Output for 7.0.8
0.0095539093017578
Output for 5.4.40, 7.0.7
0.0090329647064209
Output for 7.0.6
0.0080609321594238
Output for 7.0.5
0.0083761215209961
Output for 7.0.4
0.0059590339660645
Output for 7.0.3
0.0053920745849609
Output for 7.0.2
0.0059041976928711
Output for 7.0.1
0.0056471824645996
Output for 7.0.0
0.0057089328765869
Output for 5.6.28
0.018336057662964
Output for 5.6.25
0.01146411895752
Output for 5.6.24
0.012571096420288
Output for 5.6.23
0.012994050979614
Output for 5.6.22
0.0095658302307129
Output for 5.6.21
0.011435985565186
Output for 5.6.20
0.0093820095062256
Output for 5.6.19
0.014652967453003
Output for 5.6.18
0.010610103607178
Output for 5.6.17
0.010102033615112
Output for 5.6.16
0.0089540481567383
Output for 5.6.15
0.0088770389556885
Output for 5.6.14
0.010623931884766
Output for 5.6.13
0.0096180438995361
Output for 5.6.12
0.0084569454193115
Output for 5.6.11
0.0075180530548096
Output for 5.6.10
0.01001501083374
Output for 5.6.9
0.0087211132049561
Output for 5.6.8
0.0081229209899902
Output for 5.6.7
0.0084729194641113
Output for 5.6.6
0.010267019271851
Output for 5.6.5
0.0078628063201904
Output for 5.6.4
0.0082929134368896
Output for 5.6.3
0.0081770420074463
Output for 5.6.2
0.0080649852752686
Output for 5.6.1
0.0096490383148193
Output for 5.6.0
0.0083458423614502
Output for 5.5.38
0.01108193397522
Output for 5.5.37
0.010257959365845
Output for 5.5.36
0.011448860168457
Output for 5.5.35
0.01033616065979
Output for 5.5.34
0.013013124465942
Output for 5.5.33
0.0095350742340088
Output for 5.5.32
0.0086212158203125
Output for 5.5.31
0.007922887802124
Output for 5.5.30
0.012619018554688
Output for 5.5.29
0.0083580017089844
Output for 5.5.28
0.0079290866851807
Output for 5.5.27
0.0080928802490234
Output for 5.5.26
0.009270191192627
Output for 5.5.25
0.0079641342163086
Output for 5.5.24
0.0087428092956543
Output for 5.5.23
0.0087001323699951
Output for 5.5.22
0.0070641040802002
Output for 5.5.21
0.0083789825439453
Output for 5.5.19
0.0086178779602051
Output for 5.5.18
0.0067009925842285
Output for 5.5.16
0.008558988571167
Output for 5.5.15
0.013127088546753
Output for 5.5.14
0.010065078735352
Output for 5.5.13
0.012338876724243
Output for 5.5.12
0.013489007949829
Output for 5.5.11
0.013386011123657
Output for 5.5.10
0.010699987411499
Output for 5.5.9
0.013484001159668
Output for 5.5.8
0.012151002883911
Output for 5.5.7
0.012319087982178
Output for 5.5.6
0.013618946075439
Output for 5.5.5
0.0094881057739258
Output for 5.5.4
0.0084609985351562
Output for 5.5.3
0.011958122253418
Output for 5.5.2
0.01045298576355
Output for 5.5.1
0.011641979217529
Output for 5.5.0
0.010274171829224
Output for 5.4.45
0.0088930130004883
Output for 5.4.44
0.012102127075195
Output for 5.4.43
0.0078978538513184
Output for 5.4.42
0.0077540874481201
Output for 5.4.41
0.0076260566711426
Output for 5.4.39
0.0099780559539795
Output for 5.4.38
0.0080299377441406
Output for 5.4.37
0.0093071460723877
Output for 5.4.36
0.0074927806854248
Output for 5.4.35
0.0064070224761963
Output for 5.4.34
0.0080699920654297
Output for 5.4.32
0.009070873260498
Output for 5.4.31
0.0081100463867188
Output for 5.4.30
0.011096000671387
Output for 5.4.29
0.01127290725708
Output for 5.4.28
0.010422945022583
Output for 5.4.27
0.013788223266602
Output for 5.4.26
0.0099921226501465
Output for 5.4.25
0.010825157165527
Output for 5.4.24
0.01338791847229
Output for 5.4.23
0.0081779956817627
Output for 5.4.22
0.0075490474700928
Output for 5.4.21
0.01125693321228
Output for 5.4.20
0.012546062469482
Output for 5.4.19
0.0088040828704834
Output for 5.4.18
0.0088610649108887
Output for 5.4.17
0.010642051696777
Output for 5.4.16
0.012331962585449
Output for 5.4.15
0.013339996337891
Output for 5.4.14
0.011608839035034
Output for 5.4.13
0.010087966918945
Output for 5.4.12
0.012298107147217
Output for 5.4.11
0.013262033462524
Output for 5.4.10
0.01093316078186
Output for 5.4.9
0.012748956680298
Output for 5.4.8
0.012564897537231
Output for 5.4.7
0.013236999511719
Output for 5.4.6
0.010900974273682
Output for 5.4.5
0.0096681118011475
Output for 5.4.4
0.010302066802979
Output for 5.4.3
0.0088000297546387
Output for 5.4.2
0.012583017349243
Output for 5.4.1
0.010621070861816
Output for 5.4.0
0.012145042419434
Output for 5.3.29
0.0102379322052
Output for 5.3.28
0.012729167938232
Output for 5.3.27
0.012159109115601
Output for 5.3.26
0.010628938674927
Output for 5.3.25
0.014137029647827
Output for 5.3.24
0.015459060668945
Output for 5.3.23
0.013972997665405
Output for 5.3.22
0.015197992324829
Output for 5.3.21
0.014458894729614
Output for 5.3.20
0.015690088272095
Output for 5.3.19
0.01302695274353
Output for 5.3.18
0.011925935745239
Output for 5.3.17
0.014227151870728
Output for 5.3.16
0.012197017669678
Output for 5.3.15
0.014633893966675
Output for 5.3.14
0.015336990356445
Output for 5.3.13
0.011106014251709
Output for 5.3.12
0.01182222366333
Output for 5.3.11
0.01218581199646
Output for 5.3.10
0.012418031692505
Output for 5.3.9
0.011620998382568
Output for 5.3.8
0.011409997940063
Output for 5.3.7
0.014860868453979
Output for 5.3.6
0.014482021331787
Output for 5.3.5
0.014328002929688
Output for 5.3.4
0.0097019672393799
Output for 5.3.3
0.015570878982544
Output for 5.3.2
0.01531195640564
Output for 5.3.1
0.013976097106934
Output for 5.3.0
0.014744997024536
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_STATIC in /in/OWE4C on line 41
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STATIC in /in/OWE4C on line 41
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/OWE4C on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/OWE4C on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/OWE4C on line 5
Process exited with code 255.