ຕົວແທນ strtotime() ຂອງ PHP

ກໍານົດຄວາມພິຈາລະນາ

ການບັນທຶກຄວາມພິຈາລະນາວັນທີ ຫຼື ວັນເວລາທີ່ເປັນຕາສານອັງກິດ ເປັນເວລາສະຫະລັດ (Unix timestamp):

<?php
echo(strtotime("now") . "<br>");
echo(strtotime("15 October 1980") . "<br>");
echo(strtotime("+5 hours") . "<br>");
echo(strtotime("+1 week") . "<br>");
echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "<br>");
echo(strtotime("next Monday") . "<br>");
echo(strtotime("last Sunday"));
?>

ການດຳເນີນການ

ການອະທິບາຍ ແລະ ການນໍາໃຊ້

ຕົວແທນ strtotime() ຈະບັນທຶກຄວາມພິຈາລະນາວັນທີ ຫຼື ວັນເວລາທີ່ເປັນຕາສານອັງກິດ, ເປັນເວລາສະຫະລັດ (Unix timestamp) ມາຈາກ January 1 1970 00:00:00 GMT.

ຫັງວິທີ:ຖ້າປີສະແດງໃຫ້ດ້ວຍຮູບແບບສອງສິບ, ຈະຕິດຕາມຂອງ 0-69 ຈະຕິດຕາມສຳລັບ 2000-2069, ຈະຕິດຕາມສຳລັບ 70-100 ຈະຕິດຕາມສຳລັບ 1970-2000.

ຫັງວິທີ:ບັງຄັບກັບຕົວອັນສາຍວັນທີ່ຮູບແບບ m/d/y ຫຼື d-m-y. ຖ້າສັນຍາການແບບ / (ສູນ), ຈະໃຊ້ຮູບແບບ m/d/y ອາເມລິກາ. ຖ້າສັນຍາການແບບ - (ກາວ) ຫຼື . (ບອນ), ຈະໃຊ້ຮູບແບບ d-m-y ຢູໂຣບ. ເພື່ອຫຼີກລ່ວງຄວາມຜິດພາດ, ທ່ານຄວນໃຊ້ຮູບແບບ YYYY-MM-DD ຫຼື ການໃຊ້ຕົວແທນ date_create_from_format().

Syntax

strtotime(time,now);
Parameters Description
time Required. Specifies the date/time string.
now Optional. Specifies the timestamp to be used to calculate the return value. If the parameter is omitted, the current time is used.

Technical Details

Return Value: Returns a timestamp if successful, FALSE if it fails.
PHP Version: 4+

Update Log:

5.3.0: Now relative time formats, such as this week, last week, the previous week, the next week, specify a week from Monday to Sunday, not using the previous 7 days from the current date/time.
5.3.0 Before PHP 5.3.0, 24:00 was not a valid format, and strtotime() would return FALSE.
5.2.7 In previous versions, if you request a specific date in a month and that date is the first day of the month, it would incorrectly add one week to the timestamp returned, which has now been corrected.
5.1.0 Returns FALSE if it fails (it returns -1 in previous versions), and adds E_STRICT and E_NOTICE timezone errors.
5.0.2 Now correctly calculate "now" and other relative times based on the current time, not based on midnight of today.
5.0.0 Allow microseconds (but the microsecond value is usually ignored).
4.4.0 Before PHP 4.4, "next" was incorrectly calculated as +2. The usual solution is to use "+1".