Monday 5 December 2016

Chapter 7 (PHP) Date Command in php (How to display day and time in php)

HOW TO DISPLAY DATE AND TIME

We can show date and time in php .There is predefined date command in php with the help of that command we can see date and time.
With the help of program given below you will see how to use date command in php .

PROGRAM

<?php

echo("Date: " . date("D M d Y h:i:s") . "<br />");
?>

EXPLANATION

It is predefined command of php firstly we have to declare php tag and after that in echo we have to write like
echo("Date: " . date("D M d Y h:i:s") . "<br />");
as we know "Date: " display as same because written between" " after that we combine next with the help of . as we know dot is used for combining after that we use predefined date command function like date("D M d Y h:i:s") and after that with the help of dot we ca join it with break command.
NOW THE QUESTION IS WHAT IS THE MEANING OF ("D M d Y h:i:s")

The Meaning of D M d Y h:i:s is given below

* D - A textual representation of a day (three letters)
* M - A short textual representation of a month (three letters)
* d - The day of the month (from 01 to 31)
* Y - A four digit representation of a year
* h - 12-hour format of an hour (01 to 12)
* i - Minutes with leading zeros (00 to 59)

* s - Seconds, with leading zeros (00 to 59)

So it This way we can display date and time .

OUTPUT

THERE ARE MANY OTHER PREDEFINED CHRACTERS WHICH WE CAN USED IN DATE COMMAND 

These Chracters are  

    * d - The day of the month (from 01 to 31)
    * D - A textual representation of a day (three letters)
    * j - The day of the month without leading zeros (1 to 31)
    * l (lowercase 'L') - A full textual representation of a day
    * N - The ISO-8601 numeric representation of a day (1 for Monday through 7 for Sunday)
    * S - The English ordinal suffix for the day of the month (2 characters st, nd, rd or th. Works well with j)
    * w - A numeric representation of the day (0 for Sunday through 6 for Saturday)
    * z - The day of the year (from 0 through 365)
    * W - The ISO-8601 week number of year (weeks starting on Monday)
    * F - A full textual representation of a month (January through December)
    * m - A numeric representation of a month (from 01 to 12)
    * M - A short textual representation of a month (three letters)
    * n - A numeric representation of a month, without leading zeros (1 to 12)
    * t - The number of days in the given month
    * L - Whether it's a leap year (1 if it is a leap year, 0 otherwise)
    * o - The ISO-8601 year number
    * Y - A four digit representation of a year
    * y - A two digit representation of a year
    * a - Lowercase am or pm
    * A - Uppercase AM or PM
    * B - Swatch Internet time (000 to 999)
    * g - 12-hour format of an hour (1 to 12)
    * G - 24-hour format of an hour (0 to 23)
    * h - 12-hour format of an hour (01 to 12)
    * H - 24-hour format of an hour (00 to 23)
    * i - Minutes with leading zeros (00 to 59)
    * s - Seconds, with leading zeros (00 to 59)
    * e - The timezone identifier (Examples: UTC, Atlantic/Azores)
    * I (capital i) - Whether the date is in daylights savings time (1 if Daylight Savings Time, 0 otherwise)
    * O - Difference to Greenwich time (GMT) in hours (Example: +0100)
    * T - Timezone setting of the PHP machine (Examples: EST, MDT)
    * Z - Timezone offset in seconds. The offset west of UTC is negative, and the offset east of UTC is positive (-43200 to 43200)
    * c - The ISO-8601 date (e.g. 2004-02-12T15:19:21+00:00)
    * r - The RFC 2822 formatted date (e.g. Thu, 21 Dec 2000 16:01:07 +0200)
    * U - The seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)

WE CAN ALSO GET DEFAULT TIME ZONE 


The method or program of default time zone get is given below.


PROGRAM

<?php
echo(date_default_timezone_get());

?>

EXPLANATION

We can also get default time zone there is a command (date_default_timezone_get());
with the help of this command we can get default time zone .It is predefined command or function
simply we have to declare php tag after that in echo we have write this command and after that close php tag and run the program.

OUTPUT



WE CAN ALSO SET MANUALLY DEFAULT TIME ZONE

The program of how to set manually default time zone is given below.

PROGRAM

<?php
echo(date_default_timezone_set("Europe/Paris"));
?> 

EXPLANATION


We can also set default time zone there is command(date_default_timezone_set("Europe/Paris"));
with the help of this command we can set default time zone .It is predefined commandor function.
simply we have to declare php tag after that in echo we have write this command and after that close php tag and run the program. In this program i write Europe/Paris.You can also write this according to your region .the output 1 shows that default time zone is set.

OUTPUT






If you have any query regarding this than please post a comment.




No comments:

Post a Comment