7 February 2024

In PHP, the most common and straightforward method to convert datetime strings to timestamps is by using the strtotime() function. So even when this seems like a pointless exercise, you might actually end up using it if you are using a third party library or API that reads string time into strtotime() function. The benefit of timestamp is that it's timezone neutral.

Source code viewer
  1. // Use @timestamp format directly for datetime_string
  2. $timestamp = 1612690800; // Unix timestamp
  3. $datetime_string = '@' . $timestamp;
  5. $timestamp = strtotime($datetime_string);
Programming Language: PHP