akashpoudelnp / nepali-date-carbon
此包扩展了Carbon以支持尼泊尔日期
0.1.1
2023-02-20 13:33 UTC
Requires
- php: ^8.1
This package is auto-updated.
Last update: 2024-09-20 17:43:26 UTC
README
此包通过扩展Carbon的功能,增加了对尼泊尔日期时间的支持。使用此包,您可以轻松地在Carbon使用的公历和尼泊尔历之间转换日期和时间。
安装
您可以通过Composer使用以下命令安装:
$ composer require akashpoudelnp/nepali-date-carbon
{ "require": { "akashpoudelnp/nepali-date-carbon": "^0.1" } }
使用方法
安装和配置包后,您可以使用它就像在Laravel中使用Carbon一样。以下是一些使用此包的示例:
转换:将公历日期转换为尼泊尔日期
$date = now(); // 20 February, 2023 01:09 pm $convertedDate = $date->convertToBS()->format(); // Output: 8 Falgun, 2079 01:09:pm
此包通过允许您使用而不是导入和使用类来使用carbon实例来扩展carbon的功能。
格式
此包允许您使用标准的日期时间格式来格式化给定的日期时间。
// Assume the current nepali date is Falgun 08, 2079 now()->convertToBS()->format('d') // 8 now()->convertToBS()->format('m') // 11 now()->convertToBS()->format('F') // Falgun now()->convertToBS()->format('Y') // 2079 now()->convertToBS()->format('y') // 79
您可以使用以下任何组合来更改到所需的格式。
翻译
我们增加了一个将日期时间翻译成尼泊尔语的功能。函数 convertToBS(translate)
接受一个布尔参数,该参数将使转换的日期时间被翻译。
// ८ फागुन, २०७९ ०१:२१:pm now()->convertToBS(translate: true)->format('d F, Y h:i a')
致谢
Nepali Carbon 使用 nesbot/carbon 作为基础。