Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Add fromTimestamp method
Browse files Browse the repository at this point in the history
  • Loading branch information
meysampg committed Nov 4, 2016
1 parent fc8d5b6 commit bb945b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions IntlDateTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public function asTimestamp()
return $this->getIntlCalendar()->toDateTime()->format('U');
}

public function fromTimestamp($timestamp)
{
$dateArray = getdate($timestamp);
unset($dateArray[0]);

$this->from($dateArray);

return $this;
}

public function from($datetime = [], $locale = 'en_US', $calendar = null)
{
$datetime = $this->parseDateTime($datetime);
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ Examples
There are some examples for using `IntlDateTrait`. I think they are necessary and sufficent.

```php
$this->fromTimestamp(1504770825)->toPersian('en')->asDateTime();
// '1396/06/16, 07:53:45'

$this->fromGregorian([2017, 9, 7, 12, 23, 45])->toPersian('en')->asDateTime();
// '1396/06/16, 07:53:45'

Expand Down

0 comments on commit bb945b6

Please sign in to comment.