Core PHP

Time in Seconds and Date

This program demonstrates how to get the time in seconds and the date in a piece of code in PHP.

TimeSecondsDate.php

<?php
  $iCurrentTime = time();
  echo 'Seconds since (January 1 1970 00:00:00 GMT): '. $iCurrentTime."<br />";
  echo 'Now:       '. date('Y-m-d') ."<br />";
  // 7 days * 24 hours * 60 mins * 60 secs
  echo 'Next Week: '. date('Y-m-d', $iCurrentTime + (7*24*60*60)) ."<br />";
  // Use strtotime():
  echo 'Next Month: '. date('Y-m-d', strtotime('+1 month')) ."<br />";
?>
 

Output

 
 

© 2007–2024 XoaX.net LLC. All rights reserved.