Last active
March 31, 2024 22:07
-
-
Save ppazos/fff745766637d1fed459ef5e170a4c85 to your computer and use it in GitHub Desktop.
Create and consume millisecond timestamps in PHP and Groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Consume timestamp in Java/Groovy | |
def timestamp = ... | |
def date = new Date(timestamp) | |
println new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date) | |
// Generate milliseconds in Groovy for current date | |
def timestamp = new Date().getTime() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Generate milliseconds in PHP for current date | |
$timestamp = floor(microtime(true) * 1000); | |
// Consume the timestamp in PHP | |
// NOTE: date needs the resolution of the timestamp to be seconds not milliseconds | |
$timestamp = ... | |
echo date('Y-m-d H:i:s', floor($timestamp / 1000)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment