- Get and set the current timezone.
- Retrieve the current date/time in various formats.
- Format timestamps.
- Calculate the difference between two date/times.
- Modify a date/time by adding or subtracting intervals.
- Convert between 12-hour and 24-hour formats.
- Detect and convert date/time strings in various formats.
- Installation
- Simply include the PHTM class in your project:
require_once 'PHTM.php';
PHTM::setZone('Asia/Dhaka');
echo PHTM::getZone(); // Output: Asia/Dhaka
echo PHTM::getTime(); // Output: 2024-06-27 12:34:56
echo PHTM::getTime('l, F j, Y g:i A'); // Output: Thursday, June 27, 2024 12:34 PM
echo PHTM::setTime(1672531199, 'Y-m-d H:i:s'); // Output: 2024-01-01 00:59:59
echo PHTM::setTime('2024-06-27 12:34:56', 'd M Y, H:i'); // Output: 27 Jun 2024, 12:34
$diff = PHTM::calculate('2024-06-27 12:34:56', '2023-06-27 11:34:56');
print_r($diff);
/* Output:
Array
(
[years] => 1
[months] => 0
[days] => 0
[hours] => 1
[minutes] => 0
[seconds] => 0
)
*/
echo PHTM::modify('2024-06-27 12:34:56', '+7 days'); // Output: 2024-07-04 12:34:56
echo PHTM::modify('2024-06-27 12:34:56', '-1 year'); // Output: 2023-06-27 12:34:56
echo PHTM::to12h('2024-06-27 14:34:56'); // Output: 2:34:56 PM
echo PHTM::to24h('2024-06-27 2:34:56 PM'); // Output: 14:34:56
echo PHTM::format('2024-06-27 14:34:56', 'd/m/Y H:i'); // Output: 27/06/2024 14:34
echo PHTM::format('June 27, 2024 14:34:56', 'Y-m-d H:i:s'); // Output: 2024-06-27 14:34:56
Contributions are welcome! Please feel free to submit a pull request or open an issue on GitHub.
This project is licensed under the MIT License.