PHP code example of deviantintegral / null-date-time

1. Go to this page and download the library: Download deviantintegral/null-date-time library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

deviantintegral / null-date-time example snippets




function createTime(string $time = null): \Deviantintegral\NullDateTime\DateTimeFormatInterface
{
  if (null === $time || '' === $time) {
    return new \Deviantintegral\NullDateTime\NullDateTime();
  }

  return \Deviantintegral\NullDateTime\ConcreteDateTime::fromString($time);
}

$dateTime = createTime('now');
$dateTime->format('U'); // Will return the current Unix timestamp.
if ($dateTime instanceof \Deviantintegral\NullDateTime\ConcreteDateTimeInterface) {
  $dateTime->getDateTime()->getOffset(); // Call any of the usual \DateTime methods.
}

$dateTime = createTime('');
$dateTime->format('U'); // Will return an empty string.