SnowflakeService.php 298 B

123456789101112131415161718
  1. <?php
  2. namespace App\Services;
  3. use Illuminate\Support\Carbon;
  4. class SnowflakeService {
  5. public static function byDate(Carbon $ts = null)
  6. {
  7. $ts = $ts ? now()->parse($ts)->timestamp : microtime(true);
  8. return ((round($ts * 1000) - 1549756800000) << 22)
  9. | (1 << 17)
  10. | (1 << 12)
  11. | 0;
  12. }
  13. }