]> 91.132.146.200 Git - dolphin.git/commitdiff
timeticks in php
authorBanana <banana@mirage>
Sat, 21 Dec 2019 18:26:14 +0000 (19:26 +0100)
committerBanana <banana@mirage>
Sat, 21 Dec 2019 18:26:14 +0000 (19:26 +0100)
single-functions/high-precision-unix-timestamp.php [new file with mode: 0644]

diff --git a/single-functions/high-precision-unix-timestamp.php b/single-functions/high-precision-unix-timestamp.php
new file mode 100644 (file)
index 0000000..b11da01
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+/**
+ *  dolphin. Collection of useful PHP skeletons.
+ *  Copyright (C) 2019  Johannes 'Banana' Keßler
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
+ *
+ * You should have received a copy of the
+ * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+ * along with this program.  If not, see http://www.sun.com/cddl/cddl.html
+ */
+
+/**
+ * creates a high-precision UNIX timestamp
+ * https://docs.microsoft.com/en-us/dotnet/api/system.datetime.ticks
+ *
+ * @return int
+ */
+static function timeticks() {
+       $mtime = microtime();
+       $parts = explode(' ', $mtime);
+       
+       # Using a string here to prevent overflow
+       # PHP converts it to a double
+       return sprintf('%d%03d', $parts[1], $parts[0] * 1000);
+}