<?php include __DIR__ . "/../src/StefanUrban/DateTime.php"; include __DIR__ . "/../src/StefanUrban/DateInterval.php"; $time = "2012-01-01 12:15:11.0111"; $now = new StefanUrban\DateTime($time); $timestamp = $now->getTimestamp(); $now2 = new StefanUrban\DateTime(); $now2->setTimestamp($timestamp); echo ' soll: ' . $now->format('Y-m-d H:i:s.u'); echo "\n"; echo ' soll: ' . $now2->format('Y-m-d H:i:s.u'); echo "\n";
<?php include __DIR__ . "/../src/StefanUrban/DateTime.php"; include __DIR__ . "/../src/StefanUrban/DateInterval.php"; $time = "2012-01-01 12:15:11.0111"; $pastTime = new StefanUrban\DateTime($time); $now = new StefanUrban\DateTime(); $diff1000plus = $now->diff($pastTime); $diff0 = $now->diff($now); echo ' tage seit 01.01.2012: ' . $diff1000plus->days; echo "\n"; echo ' 0 tage: ' . $diff0->days; echo "\n";
<?php include __DIR__ . "/../src/StefanUrban/DateTime.php"; include __DIR__ . "/../src/StefanUrban/DateInterval.php"; $time = "2012-01-01 12:15:11.95"; $time = new StefanUrban\DateTime($time); $interval = new StefanUrban\DateInterval(0.1); echo $time->format('d.m.Y | H:i:s.u') . ' + 0.1 s ='; echo "\n"; $time->add($interval); $out = $time->format('d.m.Y | H:i:s.u'); echo $out . ' - ' . ($out == "01.01.2012 | 12:15:12.050000" ? 'ok' : 'not ok'); echo "\n"; echo '-----------------------------------'; echo "\n"; $time = "2012-01-01 12:15:11.05"; $time = new StefanUrban\DateTime($time); $interval = new StefanUrban\DateInterval(1.1); echo $time->format('d.m.Y | H:i:s.u') . ' - 1.1 s ='; echo "\n"; $time->sub($interval); $out = $time->format('d.m.Y | H:i:s.u'); echo $out . ' - ' . ($out == "01.01.2012 | 12:15:09.950000" ? 'ok' : 'not ok'); echo "\n";
<?php include __DIR__ . "/../src/StefanUrban/DateTime.php"; include __DIR__ . "/../src/StefanUrban/DateInterval.php"; $time1 = new \StefanUrban\DateTime(); usleep(512 * 1000); $time2 = new \StefanUrban\DateTime(); $diff = $time1->diff($time2); echo $diff->format('%H:%I:%S:%U'); echo "\n";
usleep(200 * 1000); $dt = new \StefanUrban\DateTime(); echo "\n\n" . 'test #1.3: init with now (+200ms)'; echo "\n"; echo ' now: ' . $dt->format('d.m.Y | H:i:s.u'); echo "\n"; // Now + 300ms usleep(300 * 1000); $dt = new \StefanUrban\DateTime(); echo "\n\n" . 'test #1.4: init with now (+300ms)'; echo "\n"; echo ' now: ' . $dt->format('d.m.Y | H:i:s.u'); echo "\n"; // Specific point in time $time = '2012-08-22 14:21:58.11'; $dt = new \StefanUrban\DateTime($time); echo "\n\n" . 'test #2: init with constructor'; echo "\n"; echo ' soll: ' . $time; echo "\n"; echo ' ist: ' . $dt->format('Y-m-d H:i:s.u'); echo "\n"; // Specific point in time from static constructor $time = '2012-08-22 14:21:58.023114'; $dt = \StefanUrban\DateTime::createFromFormat('Y-m-d H:i:s.u', $time); echo "\n\n" . 'test #3: (init with static function)'; echo "\n"; echo ' soll: ' . $time; echo "\n"; echo ' ist: ' . $dt->format('Y-m-d H:i:s.u'); echo "\n";
<?php include __DIR__ . "/../src/StefanUrban/DateTime.php"; include __DIR__ . "/../src/StefanUrban/DateInterval.php"; $diff = new StefanUrban\DateInterval(2 * 60 * 60); $now = new StefanUrban\DateTime(); echo $now->format('Y-m-d H:i:s') . "\n"; $now->add($diff); echo $now->format('Y-m-d H:i:s') . "\n";