iandyck / carbon
DateTime的API扩展,支持281种不同的语言。
2.58.9
2022-05-05 14:14 UTC
Requires
- php: ^7.1.8 || ^8.0
- ext-json: *
- iandyck/translation: ^6.0
- symfony/polyfill-mbstring: ^1.0
- symfony/polyfill-php80: ^1.16
Requires (Dev)
- doctrine/dbal: ^2.0 || ^3.0
- doctrine/orm: ^2.7
- friendsofphp/php-cs-fixer: ^3.0
- kylekatarnls/multi-tester: ^2.0
- phpmd/phpmd: ^2.9
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^0.12.54 || ^1.0
- phpunit/php-file-iterator: ^2.0.5
- phpunit/phpunit: ^7.5.20 || ^8.5.23
- squizlabs/php_codesniffer: ^3.4
- 3.x-dev
- dev-master / 2.x-dev
- 2.58.9
- 2.58.0
- 2.57.0
- 2.56.0
- 2.55.2
- 2.55.1
- 2.55.0
- 2.54.0
- 2.53.1
- 2.53.0
- 2.52.0
- 2.51.1
- 2.51.0
- 2.50.0
- 2.49.0
- 2.48.1
- 2.48.0
- 2.47.1
- 2.47.0
- 2.46.0
- 2.45.1
- 2.45.0
- 2.44.0
- 2.43.0
- 2.42.0
- 2.41.5
- 2.41.4
- 2.41.3
- 2.41.2
- 2.41.1
- 2.41.0
- 2.40.1
- 2.40.0
- 2.39.2
- 2.39.1
- 2.39.0
- 2.38.0
- 2.37.0
- 2.36.1
- 2.36.0
- 2.35.0
- 2.34.2
- 2.34.1
- 2.34.0
- 2.33.0
- 2.32.2
- 2.32.1
- 2.32.0
- 2.31.0
- 2.30.0
- 2.29.1
- 2.29.0
- 2.28.0
- 2.28.0-beta.1
- 2.27.0
- 2.26.0
- 2.25.3
- 2.25.2
- 2.25.1
- 2.25.0
- 2.25.0-beta.3
- 2.25.0-beta.2
- 2.25.0-beta.1
- 2.24.0
- 2.24.0-beta.4
- 2.24.0-beta.3
- 2.24.0-beta.2
- 2.24.0-beta.1
- 2.23.1
- 2.23.0
- 2.23.0-beta.4
- 2.23.0-beta.3
- 2.23.0-beta.2
- 2.23.0-beta.1
- 2.22.3
- 2.22.2
- 2.22.1
- 2.22.0
- 2.22.0-beta.3
- 2.22.0-beta.2
- 2.22.0-beta.1
- 2.21.3
- 2.21.2
- 2.21.1
- 2.21.0
- 2.20.0
- 2.19.2
- 2.19.1
- 2.19.0
- 2.18.0
- 2.17.1
- 2.17.0
- 2.16.3
- 2.16.2
- 2.16.1
- 2.16.0
- 2.15.0
- 2.14.2
- 2.14.1
- 2.14.0
- 2.13.0
- 2.12.0
- 2.11.0
- 2.10.1
- 2.10.0
- 2.9.1
- 2.9.0
- 2.8.0
- 2.7.0
- 2.6.1
- 2.6.0
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.1
- 2.4.0
- 2.3.1
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.1
- 2.0.0
- 2.0.0-beta.6
- 2.0.0-beta.5
- 2.0.0-beta.4
- 2.0.0-beta.3
- 2.0.0-beta.2
- 2.0.0-beta.1
- 1.39.1
- 1.39.0
- 1.38.4
- 1.38.3
- 1.38.2
- 1.38.1
- 1.38.0
- 1.37.1
- 1.37.0
- 1.36.2
- 1.36.1
- 1.36.0
- 1.35.1
- 1.35.0
- 1.34.4
- 1.34.3
- 1.34.2
- 1.34.1
- 1.34.0
- 1.33.0
- 1.32.0
- 1.31.1
- 1.31.0
- 1.30.0
- 1.29.2
- 1.29.1
- 1.29.0
- 1.28.0
- 1.27.0
- 1.26.6
- 1.26.5
- 1.26.4
- 1.26.3
- 1.26.2
- 1.26.1
- 1.26.0
- 1.25.3
- 1.25.1
- 1.25.0
- 1.24.2
- 1.24.1
- 1.24.0
- 1.23.0
- 1.22.1
- 1.22.0
- 1.21.0
- 1.20.0
- 1.19.0
- 1.18.0
- 1.17.0
- 1.16.0
- 1.15.0
- 1.14.0
- 1.13.0
- 1.12.0
- 1.11.0
- 1.10.0
- 1.9.0
- 1.8.0
- 1.7.0
- 1.6.0
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.1
- 1.0.0
- dev-fix/sk-translations
- dev-feature/rename-real-to-UTC
This package is auto-updated.
Last update: 2024-09-05 19:35:27 UTC
README
一个国际化的PHP DateTime扩展。 https://carbon.nesbot.com
<?php use Carbon\Carbon; printf("Right now is %s", Carbon::now()->toDateTimeString()); printf("Right now in Vancouver is %s", Carbon::now('America/Vancouver')); //implicit __toString() $tomorrow = Carbon::now()->addDay(); $lastWeek = Carbon::now()->subWeek(); $nextSummerOlympics = Carbon::createFromDate(2016)->addYears(4); $officialDate = Carbon::now()->toRfc2822String(); $howOldAmI = Carbon::createFromDate(1975, 5, 21)->age; $noonTodayLondonTime = Carbon::createFromTime(12, 0, 0, 'Europe/London'); $internetWillBlowUpOn = Carbon::create(2038, 01, 19, 3, 14, 7, 'GMT'); // Don't really want this to happen so mock now Carbon::setTestNow(Carbon::createFromDate(2000, 1, 1)); // comparisons are always done in UTC if (Carbon::now()->gte($internetWillBlowUpOn)) { die(); } // Phew! Return to normal behaviour Carbon::setTestNow(); if (Carbon::now()->isWeekend()) { echo 'Party!'; } // Over 200 languages (and over 500 regional variants) supported: echo Carbon::now()->subMinutes(2)->diffForHumans(); // '2 minutes ago' echo Carbon::now()->subMinutes(2)->locale('zh_CN')->diffForHumans(); // '2分钟前' echo Carbon::parse('2019-07-23 14:51')->isoFormat('LLLL'); // 'Tuesday, July 23, 2019 2:51 PM' echo Carbon::parse('2019-07-23 14:51')->locale('fr_FR')->isoFormat('LLLL'); // 'mardi 23 juillet 2019 14:51' // ... but also does 'from now', 'after' and 'before' // rolling up to seconds, minutes, hours, days, months, years $daysSinceEpoch = Carbon::createFromTimestamp(0)->diffInDays();
通过Tidelift订阅获取支持的nesbot/carbon
安装
使用Composer
$ composer require nesbot/carbon
{ "require": { "nesbot/carbon": "^2.16" } }
<?php require 'vendor/autoload.php'; use Carbon\Carbon; printf("Now: %s", Carbon::now());
不使用Composer
为什么不使用composer?下载Carbon的最新版本,并将ZIP归档的内容放入项目的目录中。然后需要加载所有类和依赖项的文件autoload.php
。
<?php require 'path-to-Carbon-directory/autoload.php'; use Carbon\Carbon; printf("Now: %s", Carbon::now());
文档
https://carbon.nesbot.com/docs
安全联系方式
报告安全漏洞,请使用Tidelift安全联系方式。Tidelift将协调修复和披露。
致谢
贡献者
本项目得以存在,归功于所有贡献者。
翻译者
赞助商
通过成为赞助商来支持本项目。您的标志将显示在此处,并提供到您网站的链接。
[成为赞助商]
支持者
感谢所有支持者!🙏
[成为支持者]
Carbon企业版
作为Tidelift订阅的一部分提供。
Carbon的维护者以及成千上万的其他包的维护者正在与Tidelift合作,为您使用的构建应用程序的开源依赖项提供商业支持和维护。节省时间,降低风险,提高代码质量,同时支付您使用的确切依赖项的维护者。 了解更多。