How To Find Out The Time On The Server

Table of contents:

How To Find Out The Time On The Server
How To Find Out The Time On The Server

Video: How To Find Out The Time On The Server

Video: How To Find Out The Time On The Server
Video: How to find out the last Shutdown time of Windows 10 PC 2024, December
Anonim

Your site's server can be geographically located anywhere, so its time does not necessarily coincide with your local time. Also, even if you and the server are in the same room, the server's time settings may differ from your local time. You can find out the current server time using a simple PHP script. Today, every hosting company provides customers with the ability to use this language.

How to find out the time on the server
How to find out the time on the server

Instructions

Step 1

A PHP function that reads the date and time from the server variables at the time of its execution is generally written as follows: date () It can be passed a template according to which the function will format the result of its work. Taking into account this template, the function can look like this: date ('H: i: s dmY'); When using the template specified here, the current date and time will be presented as follows: 22: 09: 06 2011-30-05 Designations used in this format ('H: i: s dmY'): - letter H puts the current time clock in the first place in the format from 00 to 23. If the number of hours is less than 10, then 0 will be inserted before it (for example, 05). If the letter H is replaced by G, then the zero will not be added. You can change the case of letters - instead of H and G, write h and g. In this case, hours will be represented in the format from 0 to 12. That is, 22 hours will be represented as 10 o'clock in the afternoon; - letter i shows where the minutes of the current time should be displayed; - letter s marks the position of seconds in writing the date and time; - letter d indicates the location of the day of the month in two-digit format (for example, 02). If you replace d with j, then zero will not be added - the format of numbers will become unambiguous (i.e. not 02, but just 2); - letter m indicates that this position of the function should be replaced with the ordinal number of the month in the format from 01 to 12 Replacing m with n will change the format to 1 - 12, and replacing it with the letter F will use the full month name (for example, "August"). The letter M stands for the abbreviated name of the month (ie "Aug" instead of "August"); - the letter y stands for the full four-digit representation of the year number. If you change its case (y), then the year number will be reduced to the last two digits (that is, instead of 2011, there will be 11); Of the other useful formatting options for this function, you can mark the letter I - it allows you to specify in the date the action on the daylight saving time server ", And the letter O shows the server time zone (ie, the hour shift relative to the Greenwich meridian). The letter W calculates the ordinal number of the current week in the year, and w and D display the day of the week in numerical and text form, respectively. Using the letter L, you can add a leap year indicator to the date format.

Step 2

This information about the date () function is enough to get you to the practical part of solving the problem. Step 1: Start a text editor and create a new document. Step 2: Write a script from just one line of PHP code to the document: Make sure that the "< "is the very first character in this document and there are no spaces or blank lines in front of it. Step 3: Based on the information above, compose the date and time output format that suits you best, and replace the required characters inside the quotes in the function code. Step 4: save the compiled document to a file with the php extension (for example, getDate.php) and upload it to the server. Step 5: type the URL of the loaded page in the browser. You will see the current date and time on the server in the specified format.

Recommended: