php date time stamp transfer

  1. UNIX timestamp and date format is two times we often deal with representation, Unix timestamp storage, ease of handling, but not intuitive, visual format dates, but deal with it not as good as Unix timestamp so freely, so sometimes you need mutual conversion, are given below PHP date stamp transfer, the MySQL date several conversion mode conversion function for mutual conversion
  2. Written PHP + MySQL programmers are aware of the time difference, UNIX timestamp and date format is two times we often deal with representation, Unix timestamp storage, ease of handling, but not intuitive, visual format dates, but deal it is better to Unix timestamp so freely, so sometimes need to convert each other, give each other some way to convert the conversion below.
  3. First, in the MySQL completion
  4.   
  5. In this way MySQL query conversion, do not take advantage of PHP parsing time parser, fast, disadvantage is only used in the database query, there are limitations.
  6. 1.  the UNIX timestamp into a date using the function:  FROM_UNIXTIME ()
  7. The general form: SELECT  FROM_UNIXTIME ( 1,156,219,870 );
  8. 2. The date is converted to UNIX timestamp with the function:  UNIX_TIMESTAMP () 
  9. The general form: the Select  UNIX_TIMESTAMP ( '2006-11-04 12:23:00');
  10. For example: mysql query number of records of the day:
  11. $sql=”select * from message Where DATE_FORMAT(FROM_UNIXTIME(chattime),'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d') order by id desc”;
  12. Of course, you can also choose to convert in PHP, the following talk about conversion in PHP.
  13. Second, completed in PHP
  14.   
  15. This is accomplished in PHP conversion program, the advantage is not whether the data obtained can query the database conversion, the conversion of unlimited scope, the disadvantage is occupied by PHP parser parse time, speed is relatively slow.
  16. 1. UNIX date stamp is converted to a function: date ()
  17. General form: DATE ( ' the Y - m - D H : I : S ', 1,156,219,870);
  18. 2. The date stamp is converted to UNIX with the function: strtotime ()
  19. General form: strtotime ( ' 2010 - 03 - 24 08 : 15 : 42 is '); 
  20. php date stamp turn, is converted into the specified date stamp
  21. php date stamp turn, converted into a specified date stamp, PHP regular tasks.
  22. These two days to achieve this functionality:
  23. When it reaches a certain condition, have the server send text messages to the user, the number is more than.
  24. The basic idea: linux timing of scanning, if the condition of the user, send SMS messages.
  25. However, in order to prevent disturb the user is required only during the day 8: 00 to send text messages, how to get to this time of day interval: 00-20?
  26. The following code:
  27. code show as below:
  28. <?
  29. $y=date("Y",time());
  30. $m=date("m",time());
  31. $d=date("d",time());
  32. $start_time = mktime(9, 0, 0, $m, $d ,$y);
  33. $end_time = mktime(19, 0, 0, $m, $d ,$y);
  34. $time = time();
  35. if($time >= $start_time && $time <= $end_time)
  36. {
  37. // do something....
  38. }
  39. ?> 

Guess you like

Origin www.cnblogs.com/yuanscn/p/10958402.html