Modify the above program bit more to the human-readable date along with these timestamps. It totally depends on when we run this program. Output at the time of running the above code, you will see the different outputs. As we know changing the string date to the timestamp is the main function of the strtotime() function.Ĭhanging the string date to the actual date. Example #2Ĭhange the dates to the timestamp. We will see the different output as per the current date. Please note that, this output was at the time of writing and running this program. Here we begin with the combing above code as a program and see the output. Given below are the examples mentioned: Example #1 Now, we will use another function to get the human-readable date from this timestamp. This line of code will give us the current timestamp. For this, first, we have to get the current timestamp then we can use the other date function to get the exact date from that timestamp. We can simply follow the syntax of this function and can start using it as per our business requirements.įor Example: If someone wants to know the current date (means which date is going on today) we can use this function. There are no additional plugins or the extensions are required before using this function. This function is one of the basic functions in the PHP language. Till now, various extensions have been made in this function. PHP support this function from very earlier from version 4+.The second parameter (Now) is an optional one.This parameter is the required one and we can’t skip while working with this function. The first parameter (DateTime) is all about the date/time in the string format.PHP program to convert English Date to UNIX timestamp then normal date " Įcho "Current Date Time : ".date("Y-m-d h:i:s",$dateType_2) Įcho "Current Date Time : ".date("Y-m-d h:i:s",$dateType_3) Įcho "Current Date Time : ".date("Y-m-d h:i:s",$dateType_4) Įcho "Current Date Time : ".date("Y-m-d h:i:s",$dateType_5) Įcho "Current Date Time : ".date("Y-m-d h:i:s",$dateType_6) Įcho "Current Date Time : ".date("Y-m-d h:i:s",$dateType_7) Įcho "Current Date Time : ".date("Y-m-d h:i:s",$dateType_8) Įcho "Current Date Time : ".date("Y-m-d h:i:s",$dateType_9) Įcho "Current Date Time : ".date("Y-m-d h:i:s",$dateType_10) Įcho "Current Date Time : ". PHP program to convert UNIX timestamp into date format Ĭonvert English Date to UNIX timestamp " Įcho "Current Date Time : ".$dateType_10 Įcho "Current Date Time : ".$dateType_11 Note: The output of below programs may vary depending on the date/time the code is compiled Note: PHP versions previous to PHP 5.1.0, would return -1 on failure. The strtotime() returns timestamp on success and FALSE on failure. Specifies the timestamp which is used as a base to calculate relative dates Specifies the English textual date/time string The strtotime() function takes two parameters as shown above in the syntax. Syntax: strtotime ( string $time, int $now) Unix timesmap is the total number of seconds completed since Janu00:00:00 GMT. Therefore to avoid any confusion, you should use ISO 8601 (YYYY-MM-DD) dates or DateTime::createFromFormat() when possible.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |