nextcloud-memento/lib/Controller/ datetimeConversion.php
19 lines
668 B

  1. <?php
  2. namespace OCA\Memento\Controller;
  3. use DateTime;
  4. function datetimeTimestampToString($timestamp) {
  5. $datetimeObject = new DateTime("@$timestamp"); // will supposedly have the timezone set to UTC.
  6. // The spec requires exactly 'GMT' without numeric offset, so we cannot use DateTime::RFC1123.
  7. $datetimeString = $datetimeObject->format("D, d M Y H:i:s") . " GMT";
  8. return $datetimeString;
  9. }
  10. function datetimeStringToTimestamp($datetimeString) {
  11. // Be tolerant and allow any RFC1123 formatted datetime string.
  12. $datetimeObject = DateTime::createFromFormat(DateTime::RFC1123, $datetimeString);
  13. $timestamp = $datetimeObject->getTimestamp();
  14. return $timestamp;
  15. }