Posted on Updated on

Getting the Time Stamp with time()

PHP’s time() function gives you all the information that you need about the current dateand time. It requires no arguments but returns an integer.The integer returned by time() represents the number of seconds elapsed since midnightGMT on January 1, 1970. This moment is known as the UNIX epoch, and the number ofseconds that have elapsed since then is referred to as a time stamp.

<?php

print time();

?>

This is something difficult to understand. But PHP offers excellent tools to convert a timestamp into a form that humans are comfortable with.Converting a Time Stamp with getdate()The function getdate() optionally accepts a timestamp and returns an associative arraycontaining information about the date. If you omit the time stamp, it works with thecurrent time stamp as returned by time().The following table lists the elements contained in the array returned by getdate().

Key Description Example

secondsSeconds past the minutes (0-59) 20

minutesMinutes past the hour (0 – 59) 29

hoursHours of the day (0 – 23) 22

mday Day of the month (1 – 31) 11

wday Day of the week (0 – 6) 4

mon Month of the year (1 – 12) 7

yearYear (4 digits) 1997

yday Day of year ( 0 – 365 ) 19

weekday Day of the week Thursday

monthMonth of the year January

0 Timestamp 948370048

Now you have complete control over date and time. You can format this date and time inwhatever format you want.

Try out the following example.

<?php

$date_array = getdate();

foreach ( $date_array as $key => $val )

{

print “$key = $val<br />”;

}

$formated_date = “Today’s date: “;

$formated_date .= $date_array[mday] . “/”;

$formated_date .= $date_array[mon] . “/”;

$formated_date .= $date_array[year];

print $formated_date;

?>

For more details and queries please feel free to email, visit or call us. Wishing you the very best for all your future endeavors.

Helpline: 9814666333, 8699444666

Email:info@technocampus.co.in

**************************************************************************************************************

Please fill the FORM and we shall contact you soon.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s