strtotime (PHP)

<?php
$date_now = date('Y-m-d', strtotime('+1 years'));
$date_now = date('Y-m-d', strtotime("-1 day", strtotime($date_now)));
echo $date_now;
?>

將英文文本日期時間解析為Unix 時間戳:

<?php
    echo(strtotime("now")); //現在時間
    echo(strtotime("3 October 2005")); //2015-10-03
    echo(strtotime("+5 hours")); //現在時間+5小時
    echo(strtotime("+1 week")); //現在時間+1星期
    echo(strtotime("+1 week 3 days 7 hours 5 seconds")); //現在時間 +1星期3天7小時5秒
    echo(strtotime("next Monday")); //下個星期的星期一
    echo(strtotime("last Sunday")); //上個星期的星期天
    //輸出
    //1530144600
    //1473004800
    //1530162600
    //1530749400
    //1531033805
    //1530460800
    //1529769600
?>

日期時間相減
strtotime()轉換成為Unix時間戳,可直接使用兩個時間戳相減計算時間差。

<?php
    echo $time1="2015-11-18 23:00:00";
    echo $time2="2015-11-22 05:00:00";

    echo (strtotime($time1) - strtotime($time2)); //計算相差之秒數
    echo (strtotime($time1) - strtotime($time2))/ (60); //計算相差之分鐘數
    echo (strtotime($time1) - strtotime($time2))/ (60*60); //計算相差之小時數
    echo (strtotime($time1) - strtotime($time2))/ (60*60*24); //計算相差之天數
?>

//計算相差之分鐘數

<?php
$to_time = strtotime("2017-09-12 00:00:00");
$from_time = strtotime("2017-09-12 02:00:00");
echo round(abs($to_time - $from_time) / 60,2). " minute";
?>

strtotime()轉換為日期格式date()

<?php
    //目前時間 加 1小時
    echo date('Y-m-d H:i:s', strtotime('+1 hours'));
    //2017-01-19 13:17:07
?>

54 thoughts on “strtotime (PHP)

  1. Pingback: Generic viagra usa

  2. Pingback: cialis

  3. Pingback: discount cialis

  4. Pingback: cialis super active

  5. Pingback: Buy pfizer viagra online

  6. Pingback: Canadian viagra and healthcare

  7. Pingback: cialis online canada

  8. Pingback: over the counter cialis

  9. Pingback: cialis walmart

  10. Pingback: cialis daily cost

  11. Pingback: levitra vs cialis

  12. Pingback: viagra for sale

  13. Pingback: online pharmacy viagra

  14. Pingback: ed medications

  15. Pingback: ed meds online

  16. Pingback: best over the counter ed pills

  17. Pingback: canada online pharmacy

  18. Pingback: cialis visa

  19. Pingback: levitra dosage

  20. Pingback: levitra 20 mg

  21. Pingback: vardenafil dosage

  22. Pingback: purchase viagra

  23. Pingback: san manuel casino online

  24. Pingback: cialis 20

  25. Pingback: generic viagra reviews

  26. Pingback: generic viagra canada

  27. Pingback: cialis online

  28. Pingback: generic cialis at walmart

  29. Pingback: Buy viagra in us

  30. Pingback: Buy generic viagra

  31. Pingback: Viagra best buy

  32. Pingback: Cialis or viagra

  33. Pingback: Buy branded viagra

  34. Pingback: cialis online daily

  35. Pingback: buy cialis cheaper online

  36. Pingback: buy cialis doctor

  37. Pingback: generic cialis 20 mg tadalafil

  38. Pingback: taking cialis soft tabs

  39. Pingback: cialis in europe

  40. Pingback: buy cialis online in canada

  41. Pingback: cialis in europe

  42. Pingback: cialis in europe

  43. Pingback: average cost of metformin

  44. Pingback: propecia india

  45. Pingback: finasteride generic

  46. Pingback: cheapest generic cialis australia

  47. Pingback: erection pills online

  48. Pingback: ed medications list

  49. Pingback: indianpharmacy com

  50. Pingback: buy cialis rush

  51. Pingback: canadian online pharmacy cialis

  52. Pingback: how to buy cialis online uk

  53. Pingback: cialis 20mg for sale

  54. Pingback: order original cialis online

發表迴響