time in PHP
time function returns number of seconds last since 01-01-1970 12:00 AM.
echo time();
for ex:
1360221790 //output
Get Today's date and time in PHP.
echo "<h2>display Current date and time using date object</h2>";
echo date("D/j/Y h:i:s a",time());
//OUTPUT:Thu/7/2013 02:23:10 am
- GET ATOM Date and time format
echo "<h3> ATOM Date format</h3>";
echo date(DATE_ATOM,time());
echo date(DATE_ATOM,time());
OUTPUT:
ATOM Date format
2013-02-07T02:23:10-05:00
- Get RSS Date and Time format
echo "<h3> RSS Date format</h3>";
echo date(DATE_RSS,time());
echo date(DATE_RSS,time());
//OUTPUT:
RSS Date format
Thu, 07 Feb 2013 02:23:10 -0500
- Get COOKIE Date and Time Format:
echo "<h3> COOKIE Date format</h3>";
echo date(DATE_COOKIE,time());
echo date(DATE_COOKIE,time());
//OUTPUT:
COOKIE Date format
Thursday, 07-Feb-13 02:23:10 EST
- Get W3C date and Time format
echo "<h3> W3C Date format</h3>";
echo date(DATE_W3C,time());
echo date(DATE_W3C,time());
//OUTPUT:
W3C Date format
2013-02-07T02:23:10-05:00
Complete Source Code
<?php
date_default_timezone_set("America/New_York");
echo "<h1> time() function in PHP</h1>";
echo "<h1>PHP gives current time in seconds since 1970 january 1 12:00AM to current time<h1>";
echo time();
echo "<h2>display Current date and time using date object</h2>";
echo date("D/j/Y h:i:s a",time());
echo "<h3> ATOM Date format</h3>";
echo date(DATE_ATOM,time());
echo "<h3> COOKIE Date format</h3>";
echo date(DATE_COOKIE,time());
echo "<h3> RSS Date format</h3>";
echo date(DATE_RSS,time());
echo "<h3> W3C Date format</h3>";
echo date(DATE_W3C,time());
?>
date_default_timezone_set("America/New_York");
echo "<h1> time() function in PHP</h1>";
echo "<h1>PHP gives current time in seconds since 1970 january 1 12:00AM to current time<h1>";
echo time();
echo "<h2>display Current date and time using date object</h2>";
echo date("D/j/Y h:i:s a",time());
echo "<h3> ATOM Date format</h3>";
echo date(DATE_ATOM,time());
echo "<h3> COOKIE Date format</h3>";
echo date(DATE_COOKIE,time());
echo "<h3> RSS Date format</h3>";
echo date(DATE_RSS,time());
echo "<h3> W3C Date format</h3>";
echo date(DATE_W3C,time());
?>
Note: You need to set date_default_timezone_set("America/New_York");
to existing values supported by PHP refer otherwise warning message will be displayed:
"Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. "
tags: time in php, get current date and time in PHP, get today's date in PHP, get Current date and time using PHP time, Get RSS date format in PHP,
Get ATOM date format in PHP,Get W3C date format in PHP,Get COOKIE date format in PHP.DateTime formats in PHP. time() function in PHP
No comments:
Post a Comment