PHP Learning notes Array and data structure 1 (Date time function and problem solving)

Source: Internet
Author: User

1 build from the simplest array in PHP:

1) Common functions:

Generate random Number:

1 Echo  Rand (1,10); // two parameters to determine the range of a random number 2 Echo  Rand (ten);// be treated as his seed, i.e. cannot give only one parameter

The result of 2 is (missing a parameter)

2) Date-time function

<?phpvar_dump (Time ());//Unix timestamp of the current time?>

This shows the result:

Example: Similar to this (provided that the value returned with the Var_dump () output)

The right way is

* Year (four digits) with uppercase Y, month months with lowercase m, days day with lowercase d middle space hour H (12 hour system) minutes I seconds S specific subdivision suggest using PHP reference book

<? PHP Echo Date ("Y-m-d h:i:s",Time ()):?>

The result of the output may not match the time you want to see (with computer time immediately)

So here's the question.

There are generally two situations

1)

A similar form appears and that's probably you. Database (Wampserver)

Specifically, the second possibility

2) The return time and the actual difference is too large, this situation may be the time zone is not set.

Two types of solutions

A, although this method is easy to write, but too restrictive. Every place (page) needs to be changed

1 <? PHP 2 date_default_timezone_set (' PRC '); 3 Echo Date ("Y-m-d h:i:s",Time()) 4 ?>

b, modify the configuration file

Open PHP. INI lookup (ctrl+f) "Date.timezone" to make it "etc/gmt-8" after the equals sign

Just remember to save (CTRL + C) if not yet, restart your database. Completed

At the same time, another way to take the current format

Echo Date("y-m-d  h:i:s   ")  //Save time for 2nd parameters  

PHP Learning notes Array and data structure 1 (Date time function and problem solving)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.