PHP Time processing function

Source: Internet
Author: User
  1. Mktime ()
  2. Convert date and time to UNIX timestamp
  3. Time ()
  4. Gets the Unix timestamp for the current time
  5. echo Date ("Y-m-d", Mktime (0,0,0,12,31,2013)). "
    ";
  6. Example: Calculates the age of a user by calculating the difference of two Unix timestamps
  7. $year = 1991;
  8. Assuming the user's birth date is 1991.07.16
  9. $month = 07;
  10. $day = 16;
  11. $brithday = Mktime (0,0,0, $month, $day, $year);
  12. Convert a user's birth date to a Unix timestamp
  13. $nowdate = time ();
  14. Get the Unix timestamp for the current time
  15. $ageunix = $nowdate-$brithday;
  16. Get the difference between timestamps
  17. $age = Floor ($ageunix/(60*60*24*365));
  18. The difference between timestamps divided by the number of seconds per year is the actual age of the user
  19. echo "The age of the user is". $age. "

    ";
  20. Date_default_timezone_set ()
  21. Setting the time zone
  22. GETDATE ()
  23. Determine the current time
  24. Gettimeofday ()
  25. Get a specific time in a day
  26. Date_sunrise ()
  27. Sunrise Time of one day
  28. Date_sunset ()
  29. Sunset time of one day
  30. Date ()
  31. Format a local time and date
  32. Microtime ()
  33. Returns the current UNIX timestamp and number of microseconds
  34. The following class calculates the execution time of a program by obtaining the execution time of two functions
  35. Class timer{
  36. Private $startTime;
  37. Private $stopTime;
  38. function __construct () {
  39. $this->starttime = 0;
  40. $this->stoptime = 0;
  41. }
  42. function Start () {
  43. $this->starttime = Microtime (true);
  44. }
  45. function Stop () {
  46. $this->stoptime = Microtime (true);
  47. }
  48. function spent () {
  49. Return round (($this->starttime-$this->stoptime), 4);
  50. }
  51. }
  52. $timer = new timer ();
  53. $timer->start ();
  54. Usleep (1000);
  55. $timer->stop ();
  56. echo "Execute script Time ". $timer->spent (). " Seconds ";
  57. ?>
Copy Code
Php
  • 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.