Repository
https://github.com/php/php-src
What Will I Learn?
- You will learn the timestamp.
- You will learn how to get the date with format using the
date()
method. - You will learn how to get and set the timezone.
- You will learn the
StrToTime()
method.
Requirements
System Requirements:
- Server support PHP , Xampp or Wamp for example
- An IDE like Sublime text.
- Browser (Chrome for example)
OS Support for PHP
- Windows
- macOS
- Linux
Required Knowledge
- HTML language
- CSS language
Difficulty
- Intermediate
Description
In this tutorial we will learn the dates and times, there is no thing almost without the notion of time " publications, comments ..etc " almost all the tasks you can specify it using the dates and the time.
Dates in PHP have always been a fundamental issue for developers, how to store, manage, manipulate dates or time intervals, most developers will say : " the timestamp ".
Today we are going to see the function date()
, is not the object date because we are going to learn the objects in the next tutorials, and we also have the timestamp, the function strtotime()
and finally the timeZone set and Get.
1- TimeStamp
In PHP to use date the start was the timestamp, the timestamp is the number of seconds that have passed since January 1, 1970, the timestamp was at the base everything in all languages. We didn't complain too much the web was not too developed, manage dates in PHP was very common (for forums) but was not very developed.
With time, the timestamp has become longer and longer, with the development of the webthe use of dates is become more frequent and more complex.
Relational database managers such as " MySQL " or " Postgres " had already shown the power of a datatype specific to dates rather than the timestamp itself, in particular because it allowed to keep only the part "date" or the part "time" ( hours, minutes, seconds).
2- Date Method
The function 'date' forms or returns the date and local time of your server, it returns a date in the form of a string in the format given by the format parameter.
The most important thing is that this function must contain a parameter, you must indicate the display or value returned by this function.
The function contains the format as parameter, the format offered by PHP with several characters.
This function accepts a second argument that corresponds to a number of seconds since the beginning of the UNIX epoch.
3- TimeZone
One of the big problems when you want to manage the hours is that everyone on earth is not at the same time. Between time zone and summer time you will quickly fall into difficult problems.
You aren't unaware that on our good old Earth there are 24 time zones,these range from -12 to +12 through Greenwich, in order to make sure that each of your users visualize your site at its own time, you must set the time zone of your site using Timezone of php.
We will see the " date_default_timezone_get()
" and " date_default_timezone_set(timezone)
" functions.
The "date_default_timezone_set(timezone)
" will change the default timezone, if the default timezone is Europe/Berlin, it will be with the timezone that you propose.
The " date_default_timezone_get()
" will retrieve the default timezone from your system, to see and fix the problem we mentioned.
4- StrToTime Method
The " strtotime()
" function tries to read a date in US English format in the time string, and turn it into a Unix timestamp.
Really the use of the timestamp is a little difficult on all if you want a date in the past, for that PHP offers this solution you can enter a date like " last year " for example in English, or something that has a relationship with time ( the time indectors we can say ) , and this function will try to understand it and return the date in place of a succession of digits that it forms the timestamp.
It accepts two parameters :
The first is the time : it's required specifies a date/time string to parse.
The second is now: it's optional, specifies The timestamp representing the current date, used for the relative calculation of dates.
Video Tutorial
Curriculum
- PHP Tutorial #11 String Methods ( Addslaches, Chr, Chop and Chunk_splite )
- PHP Tutorial #12 String Methods ( Bin2Hex, Count_Chars, Explode and Hex2Bin )
- PHP Tutorial #13 String Methods (Implode, Join, Lcfirst, Ltrim and Fprintf )
- PHP Tutorial #14 String Methods (Md5_File, Md5, Nl2br and Addcslaches )
- PHP Tutorial #15 String Methods (Number_Format, Ord, Parse_Str, Print and Printf )
- PHP Tutorial #16 String Methods (QuoteMeta, Rtrim , Sha1_file and Sha1 )
- PHP Tutorial #17 Mathematical Methods (Abs, Acos , Acosh and Asin )
- PHP Tutorial #18 ( GET and POST ) Methods and $_SERVER Variables
- PHP Tutorial #19 ( Include and Require ) , Globals Variable, Request and $_SERVER Variables
- PHP Tutorial #20 The Cookie How To Create , Modify And Delete A Cookie
- PHP Tutorial #21 The Session How To Create , Modify And Delete A Session
- PHP Tutorial #22 The Output_Buffer And How To Control It
- PHP Tutorial #23 Filters Part 1 " FILTER_VALIDATE "
- PHP Tutorial #24 Filters Part 2 " FILTER_SANITIZE "
- PHP Tutorial #25 File System Part 1 " Fopen, Fread, Fwrite and File_get_contents "
- PHP Tutorial #26 File System Part 2 and Filter Part 3
Proof of Work Done
https://github.com/alexendre-maxim/PHP-Tutorial/blob/master/date.php
Hi @alexendre-maxim
This is another great addition of video tutorial to your series.
Your presentation is clear and to the point.
As for the written text, try to write short simple sentences. People who have English as their second language tends to write run on sentences without putting in the proper punctuation.
Long run on sentences make it difficult for people to follow the text.
Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Chat with us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you for your review, @rosatravels! Keep up the good work!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you @rosatravels, Yes to understand better, sentences must be simple.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hi @alexendre-maxim!
Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you @steem-ua
Posted using Partiko Android
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey, @alexendre-maxim!
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you
Posted using Partiko Android
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit