Time

用途

时间戳助手

核心对象方法

核心类:EasySwoole\Utility\Time

startTimestamp

返回某一天开始的时间戳

  • mixed $date 字符串日期或时间戳

static function startTimestamp($date = ‘’)

例子

  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. * 输出结果:
  12. * int(1555286400)
  13. */

endTimestamp

返回某一天结束的时间戳

  • mixed $date 字符串日期或时间戳

static function endTimestamp($date = ‘’)

例子

  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. * 输出结果:
  12. * int(1555372799)
  13. */

endTimestamp

从字符串创建出 Datetime 对象

  • mixed $datetime 传入文本日期或者时间戳

static function createDateTimeClass($datetime = ‘’)

例子

  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. * 输出结果:
  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

从DateTime对象中获取年月日时分秒

  • mixed $datetime 传入文本日期或者时间戳

static function parserDateTime($dateTime)

例子

  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. * 输出结果:
  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. */