Skip to content

Commit 5eb0311

Browse files
committed
add DateTimeUtil method
1 parent 5edd294 commit 5eb0311

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Util/DateTimeUtil.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
* @package doganoo\PHPUtil\Util
3232
*/
3333
final class DateTimeUtil {
34+
/** @var string $GERMAN_DATE_TIME_FORMAT */
35+
public const GERMAN_DATE_TIME_FORMAT = "d.m.Y H:i:s";
36+
3437
/**
3538
* prevent from instantiation
3639
* StringUtil constructor.
@@ -57,4 +60,18 @@ public static function subtractHours(int $hours, \DateTime $dateTime = null): \D
5760
$dateTime->modify("-$hours hours");
5861
return $dateTime;
5962
}
63+
64+
/**
65+
* returns a string in dd.mm.YYY H:i:s that correspondents to $timestamp
66+
*
67+
* @param int $timestamp
68+
* @return string
69+
* @throws \Exception
70+
*/
71+
public static function timestampToGermanDateFormat(int $timestamp): string {
72+
$dateTime = new \DateTime();
73+
$dateTime->setTimestamp($timestamp);
74+
$format = $dateTime->format(DateTimeUtil::GERMAN_DATE_TIME_FORMAT);
75+
return $format;
76+
}
6077
}

0 commit comments

Comments
 (0)