PHP code example of dobrosite / time-service

1. Go to this page and download the library: Download dobrosite/time-service 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/ */

    

dobrosite / time-service example snippets



use DobroSite\TimeService\TimeService;

class SomeService {
  private TimeService $timeService;
  
  // Внедряем в ваш класс службу времени в качестве зависимости.
  public function __construct(TimeService $timeService)
  {
    $this->timeService = $timeService;
  }
  
  public function someMethod(): void
  {
    // Когда вам потребуется текущее время, обратитесь к службе времени:
    $currentTime = $this->timeService->getCurrentTime();
  }
}