Date
====
[![Latest Stable Version](http://img.shields.io/github/release/jenssegers/date.svg)](https://packagist.org/packages/jenssegers/date) [![Total Downloads](http://img.shields.io/packagist/dm/jenssegers/date.svg)](https://packagist.org/packages/jenssegers/date) [![Build Status](http://img.shields.io/travis/jenssegers/date.svg)](https://travis-ci.org/jenssegers/date) [![Coverage Status](https://coveralls.io/repos/github/jenssegers/date/badge.svg?branch=master)](https://coveralls.io/github/jenssegers/date?branch=master) [![Donate](https://img.shields.io/badge/donate-paypal-blue.svg)](https://www.paypal.me/jenssegers)
This date library extends [Carbon](https://github.com/briannesbitt/Carbon) with multi-language support. Methods such as `format`, `diffForHumans`, `parse`, `createFromFormat` and the new `timespan`, will now be translated based on your locale.
Installation
------------
Install using composer:
```bash
composer require jenssegers/date
```
Laravel
-------
There is a service provider included for integration with the Laravel framework. This provider will get the application locale setting and use this for translations. To register the service provider, add the following to the providers array in `config/app.php`:
```php
'Jenssegers\Date\DateServiceProvider',
```
You can also add it as a Facade in `config/app.php`:
```php
'Date' => Jenssegers\Date\Date::class,
```
Languages
---------
This package contains language files for the following languages:
- Albanian
- Arabic
- Azerbaijani
- Bangla
- Basque
- Brazilian Portuguese
- Bulgarian
- Catalan
- Croatian
- Chinese Simplified
- Chinese Traditional
- Czech
- Danish
- Dutch
- English
- Esperanto
- Estonian
- Finnish
- French
- Galician
- Georgian
- German
- Greek
- Hebrew
- Hindi
- Hungarian
- Icelandic
- Indonesian
- Italian
- Japanese
- Kazakh
- Korean
- Latvian
- Lithuanian
- Macedonian
- Malay
- Norwegian
- Nepali (नेपाली)
- Polish
- Portuguese
- Persian (Farsi)
- Romanian
- Russian
- Thai
- Serbian (latin)
- Serbian (cyrillic)
- Slovak
- Slovenian
- Spanish
- Swedish
- Turkish
- Turkmen
- Ukrainian
- Uzbek
- Vietnamese
- Welsh
Usage
-----
The Date class extends the Carbon methods such as `format` and `diffForHumans`n and translates them based on your locale:
```php
use Jenssegers\Date\Date;
Date::setLocale('nl');
echo Date::now()->format('l j F Y H:i:s'); // zondag 28 april 2013 21:58:16
echo Date::parse('-1 day')->diffForHumans(); // 1 dag geleden
```
The Date class also added some aliases and additional methods such as: `ago` which is an alias for `diffForHumans`, and the `timespan` method:
```php
echo $date->timespan(); // 3 months, 1 week, 1 day, 3 hours, 20 minutes
```
Methods such as `parse` and `createFromFormat` also support "reverse translations". When calling these methods with translated input, it will try to translate it to English before passing it to DateTime:
```php
$date = Date::createFromFormat('l d F Y', 'zaterdag 21 maart 2015');
```
Carbon
------
Carbon is the library the Date class is based on. All of the original Carbon operations are still available, check out https://github.com/briannesbitt/Carbon for more information. Here are some of the available methods:
### Creating dates
You can create Date objects just like the DateTime object (http://www.php.net/manual/en/datetime.construct.php):
```php
$date = new Date();
$date = new Date('2000-01-31');
$date = new Date('2000-01-31 12:00:00');
// With time zone
$date = new Date('2000-01-31', new DateTimeZone('Europe/Brussels'));
```
You can skip the creation of a DateTimeZone object:
```php
$date = new Date('2000-01-31', 'Europe/Brussels');
```
Create Date objects from a relative format (http://www.php.net/manual/en/datetime.formats.relative.php):
```php
$date = new Date('now');
$date = new Date('today');
$date = new Date('+1 hour');
$date = new Date('next monday');
```
This is also available using these static methods:
```php
$date = Date::parse('now');
$date = Date::now();
```
Creating a Date from a timestamp:
```php
$date = new Date(1367186296);
```
Or from an existing date or time:
```php
$date = Date::createFromDate(2000, 1, 31);
$date = Date::createFromTime(12, 0, 0);
$date = Date::create(2000, 1, 31, 12, 0, 0);
```
### Formatting Dates
You can format a Date object like the DateTime object (http://www.php.net/manual/en/function.date.php):
```php
echo Date::now()->format('Y-m-d'); // 2000-01-31
```
The Date object can be cast to a string:
```php
echo Date::now(); // 2000-01-31 12:00:00
```
Get a human readable output (alias for diffForHumans):
```php
echo $date->ago(); // 5 days ago
```
Calculate a timespan:
```php
$date = new Date('+1000 days');
echo Date::now()->timespan($date);
// 2 years, 8 months, 3 weeks, 5 days
// or even
echo Date::now()->timespan('+1000 days');
```
Get years since date:
```php
$date = new Date('-10 years');
echo $date->age; // 10
$date = new Date('+10 years');
echo $date->age; // -10
```
### Manipulating Dates
You can manipulate by using the *add* and *sub* methods, with relative intervals (http://www.php.net/manual/en/datetime.formats.relative.php):
```php
$yesterday = Date::now()->sub('1 day');
$tomorrow = Date::now()->add('1 day');
// ISO 8601
$date = Date::now()->add('P2Y4DT6H8M');
```
You can access and modify all date attributes as an object:
```php
$date->year = 2013:
$date->month = 1;
$date->day = 31;
$date->hour = 12;
$date->minute = 0;
$date->second = 0;
```
Contributing
------------
You can easily add new languages by adding a new language file to the *lang* directory. These language entries support pluralization. By using a "pipe" character, you may separate the singular and plural forms of a string:
```php
'hour' => '1 hour|:count hours',
'minute' => '1 minute|:count minutes',
'second' => '1 second|:count seconds',
```
Some languages have a different unit translation when they are used in combination with a suffix like 'ago'. For those situations you can add additional translations by adding the suffix to the unit as a key:
```php
'year' => '1 Jahr|:count Jahre',
'year_ago' => '1 Jahr|:count Jahren',
```
There is also a `generator.php` script that can be used to quickly output day and month translations for a specific locale. If you want to add a new language, this can speed up the process:
```bash
php generator.php nl_NL
```
**NOTE!** If you are adding languages, please check the rules about the capitalization of month and day names: http://meta.wikimedia.org/wiki/Capitalization_of_Wiktionary_pages#Capitalization_of_month_names
## License
Laravel Date is licensed under [The MIT License (MIT)](LICENSE).
没有合适的资源?快使用搜索试试~ 我知道了~
[示例][PHP]date-master多语言日期PHP库.zip
共68个文件
php:63个
txt:1个
md:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 137 浏览量
2021-12-15
11:36:43
上传
评论
收藏 58KB ZIP 举报
温馨提示
这个库是多国语言组成的PHP,使用哪个国家的语言可以直接进行调用,十分的方便。
资源推荐
资源详情
资源评论
收起资源包目录
[示例][PHP]date-master多语言日期PHP库.zip (68个子文件)
date-master多语言日期PHP库
php中文网下载站.url 114B
php中文网免费下载站.txt 219B
date-master
README.md 7KB
LICENSE 1KB
composer.json 1KB
src
Date.php 14KB
DateServiceProvider.php 1016B
Lang
bg.php 2KB
ko.php 1KB
eu.php 1KB
lt.php 2KB
kk.php 1KB
sw.php 1KB
it.php 1KB
zh.php 1KB
pl.php 1KB
gl.php 1KB
ja.php 1KB
eo.php 1KB
pt.php 1KB
he.php 2KB
mk.php 2KB
sk.php 2KB
fi.php 2KB
ka.php 2KB
ta.php 3KB
sv.php 1KB
bd.php 2KB
ro.php 1KB
ar.php 2KB
sr.php 2KB
lv.php 2KB
no.php 1KB
fr.php 1KB
el.php 2KB
fa.php 1KB
sq.php 1KB
cs.php 2KB
hi.php 2KB
en.php 1KB
sr-SP.php 1KB
zh-CN.php 1KB
ru.php 2KB
es.php 1KB
ca.php 1KB
et.php 2KB
tr.php 1KB
cy.php 1KB
ne.php 2KB
sl.php 2KB
vi.php 1KB
is.php 1KB
de.php 2KB
th.php 2KB
da.php 1KB
sh.php 1KB
ms.php 1KB
uk.php 2KB
hr.php 1KB
zh-TW.php 1KB
uz.php 2KB
tk.php 1KB
nl.php 2KB
hu.php 2KB
pt-BR.php 1KB
id.php 1KB
az.php 1KB
generator.php 912B
共 68 条
- 1
资源评论
神仙别闹
- 粉丝: 2687
- 资源: 7649
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功