Skip to content

Instantly share code, notes, and snippets.

@ppazos
Last active March 31, 2024 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppazos/fff745766637d1fed459ef5e170a4c85 to your computer and use it in GitHub Desktop.
Save ppazos/fff745766637d1fed459ef5e170a4c85 to your computer and use it in GitHub Desktop.
Create and consume millisecond timestamps in PHP and Groovy
// 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()
<?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