high-precision-unix-timestamp.php 805 B

123456789101112131415161718192021222324252627
  1. <?php
  2. /**
  3. * dolphin. Collection of useful PHP skeletons.
  4. * Copyright (C) 2019 Johannes 'Banana' Keßler
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
  8. *
  9. * You should have received a copy of the
  10. * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
  11. * along with this program. If not, see http://www.sun.com/cddl/cddl.html
  12. */
  13. /**
  14. * creates a high-precision UNIX timestamp
  15. * https://docs.microsoft.com/en-us/dotnet/api/system.datetime.ticks
  16. *
  17. * @return int
  18. */
  19. static function timeticks() {
  20. $mtime = microtime();
  21. $parts = explode(' ', $mtime);
  22. # Using a string here to prevent overflow
  23. # PHP converts it to a double
  24. return sprintf('%d%03d', $parts[1], $parts[0] * 1000);
  25. }