Datetime.php 702 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace UCore\Helper;
  3. use Carbon\Carbon;
  4. class Datetime
  5. {
  6. /**
  7. * 秒转时间
  8. * @param $seconds
  9. * @return string
  10. */
  11. static public function ss($seconds)
  12. {
  13. // $seconds = 86461; // 例如86461秒,可自行设置不同秒数
  14. $carbonInstance = Carbon::createFromTimestamp($seconds);
  15. $humanReadableString = $carbonInstance->diffForHumans(null, true, true);
  16. return $humanReadableString;
  17. }
  18. /**
  19. * 时间戳 转 字符串
  20. * @param $ts
  21. * @return string
  22. */
  23. public static function ts2string($ts)
  24. {
  25. return Carbon::createFromTimestamp($ts,config('app.timezone'))->toDateTimeString();
  26. }
  27. }