Php Code for getting the current time and date

Asked By 20 points N/A Posted on -
qa-featured

Hi there.

Ive been practicing php and html programming these past few weeks.

I am now currently working on some website and I just want the codes for getting the time and date.

What is the code for getting the current time and date of the viewer?

Thank you.

SHARE
Best Answer by Gideon Yasti
Best Answer
Best Answer
Answered By 0 points N/A #100498

Php Code for getting the current time and date

qa-featured

PHP has the ability to generate the date and time dynamically .  Here I added few sample of date and time script:

Script- 1 :

<?php
// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('UTC');

// Prints something like: Monday
echo date("l");

// Prints something like: Sunday 10th of February 2012 03:16:23 AM
echo date('l jS of F Y h:i:s A');

// Prints: January 10, 2012 is on a Monday
echo "January  10, 2012 is on a " . date("l", mktime(0, 0, 0, 7, 1, 200));

/* use the constants in the format parameter */
// prints something like: Mon, 15 Aug 2005 15:12:46 UTC
echo date(DATE_RFC822);

// prints something like: 2000-07-01T00:00:00+00:00
echo date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2012));
?>

Script- 2 :

<?php
// prints something like: Wednesday the 15th
echo date('l the jS');
?>

Script- 3 :

<?php
// Assuming today is May 15th, 2012, 5:16:18 pm, and that we are in the
// Mountain Standard Time (MST) Time Zone

$today = date("F j, Y, g:i a");                 // January 15, 2012, 2:10 am
$today = date("m.d.y");                         // 15.01.12
$today = date("j, n, Y");                       // 1, 3, 2001
$today = date("Ymd");                           // 20120115
$today = date('h-i-s, j-m-y, it is w Day');     // 05-16-18, 15-01-12, 1631 1618 6 Satpm01
$today = date('it is the jS day.');   // it is the 15th day.
$today = date("D M j G:i:s T Y");               // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s m is month');     // 17:03:18 m is month
$today = date("H:i:s");                         // 17:16:18
?>
 

Script- 4 :

<?php
 $b = time ();
 print date("m/d/y",$b) . "<br>";
 print date("D, F jS",$b) . "<br>";
 print date("l, F jS Y",$b) . "<br>";
 print date("g:i A",$b) . "<br>";
 print date("r",$b) . "<br>";
 print date("g:i:s A D, F jS Y",$b) . "<br>";
 ?>

I hope all of above script will help you for add date and time in your website.

Thanks

 

Answered By 10 points N/A #100500

Php Code for getting the current time and date

qa-featured

 

Php Code for getting the current time and date:
 
<?php
echo "Date and time (12 hour format): " . date("m/d/y h:m:s "); 
echo "<br />Date and time (24 hour format): " . date("m/d/y g:m:s"); 
?>
Php code to display time on a webpage
<?php
echo "Current time in 12 hour format: " . date("h:m:s "); 
echo "<br />Current time in 24 hour format: " . date("g:m:s"); 
?>
Php code to display a date on a webpage
<?php
echo "Current date:" . date("m/d/y"); 
?>

Login/Register to Answer

Related Questions