title: Time meta:

  • name: description content: Timestamp assistant
  • name: keywords content: swoole|swoole extension|swoole framework|Easyswoole|Component Library|Miscellaneous Tools|Time

Time

Use

Timestamp assistant

Core Object Class

To implement this component function you need to load the core class:

  1. EasySwoole\Utility\Time

Core Object Method

StartTimestamp

Return the timestamp starting at a certain day

  • mixed $date string date or timestamp
  1. static function startTimestamp($date = '')

:::tip

Example

:::

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: root
  5. * Date: 19-1-9
  6. * Time: 10:10
  7. */
  8. require './vendor/autoload.php';
  9. var_dump(\EasySwoole\Utility\Time::startTimestamp('2019-4-15'));
  10. /**
  11. * Output results:
  12. * int(1555286400)
  13. */

endTimestamp

返Back to the end of the day

  • mixed $date string date or timestamp
  1. static function endTimestamp($date = '')

:::tip

Example

:::

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: root
  5. * Date: 19-1-9
  6. * Time: 10:10
  7. */
  8. require './vendor/autoload.php';
  9. var_dump(\EasySwoole\Utility\Time::endTimestamp('2019-4-15'));
  10. /**
  11. * Output results:
  12. * int(1555372799)
  13. */

endTimestamp

Create a Datetime object from a string

  • mixed $datetime incoming text date or timestamp
  1. static function createDateTimeClass($datetime = '')

:::tip

Example

:::

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: root
  5. * Date: 19-1-9
  6. * Time: 10:10
  7. */
  8. require './vendor/autoload.php';
  9. var_dump(\EasySwoole\Utility\Time::createDateTimeClass('2019-4-15'));
  10. /**
  11. * Output results:
  12. * object(DateTime)#3 (3) {
  13. * ["date"]=>
  14. * string(26) "2019-04-15 00:00:00.000000"
  15. * ["timezone_type"]=>
  16. * int(1)
  17. * ["timezone"]=>
  18. * string(6) "+00:00"
  19. * }
  20. */

parserDateTime

Get the year, month, day, hour, minute, and second from the DateTime object

  • mixed $datetime incoming text date or timestamp
  1. static function parserDateTime($dateTime)

:::tip

Example

:::

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: root
  5. * Date: 19-1-9
  6. * Time: 10:10
  7. */
  8. require './vendor/autoload.php';
  9. var_dump(\EasySwoole\Utility\Time::parserDateTime('2019-4-15'));
  10. /**
  11. * Output results:
  12. * array(6) {
  13. * [0]=>
  14. * string(2) "00"
  15. * [1]=>
  16. * string(2) "00"
  17. * [2]=>
  18. * string(2) "00"
  19. * [3]=>
  20. * string(1) "4"
  21. * [4]=>
  22. * string(2) "15"
  23. * [5]=>
  24. * string(4) "2019"
  25. * }
  26. */