Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/battye/date-convert
Convert a date string from one format to another.
https://github.com/battye/date-convert
date datetime php
Last synced: 30 days ago
JSON representation
Convert a date string from one format to another.
- Host: GitHub
- URL: https://github.com/battye/date-convert
- Owner: battye
- Created: 2019-08-25T12:53:48.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-25T13:22:08.000Z (about 5 years ago)
- Last Synced: 2024-02-22T15:32:21.635Z (9 months ago)
- Topics: date, datetime, php
- Language: PHP
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Date Convert
A small library which uses the `DateTime` object to convert a date string from one format to another.## Installation
Install this library with composer, using the command `composer require battye/date-convert "~1.0"`. If you notice any bugs, please raise an issue or pull request.
### Simple Usage
The original date string must be supplied in the `date()` function.
The `from()` function should be used to indicate the format being used, while `to()` should be filled with the desired output format (in conjunction with `datetext()`).
An example usage is shown below:
use battye\date_convert\convert;
$convert = convert::date('2011-01-20 00:00:00+09')
->from('Y-m-d H:i:sT')
->to('j F y');
$datetime = $convert->datetime(); // returns a DateTime object
$datetext = $convert->datetext(); // returns 20 January 11
$timestamp = $convert->timestamp(); // returns 1295449200
### Converting TimezonesTo output a format in a different timezone, it can be specified in either of the following ways prior to calling `datetime()` or `datetext()`. Timestamps are not impacted by timezone.
$convert->timezone(new \DateTimeZone('Asia/Macau'));
$convert->timezone('Asia/Macau');
## Tests[![Build Status](https://travis-ci.com/battye/date-convert.svg?branch=master)](https://travis-ci.com/battye/date-convert)
The unit tests provide good examples of how to utilise this library and can be found in the `tests/` directory. To execute the unit tests, run:
vendor/bin/simple-phpunit tests/