bangladatetime/laravel
Composer 安装命令:
composer require bangladatetime/laravel
包简介
A Laravel package to format DateTime to Bangla and support Bangla calendar.
README 文档
README
BanglaDateTime is a Laravel package that allows you to easily format and convert DateTime to the Bangla calendar and Bangla number formats. It supports both current time and custom dates, as well as timezones.
Features
- Convert DateTime to Bangla format.
- Convert to the Bangla calendar (Bengali Era).
- Supports custom dates and timezones.
- Easy to use with a fluent API.
- Helper functions for easy access to common operations.
Installation
You can install the package via Composer:
composer require bangladatetime/laravel
Laravel Integration
To integrate BanglaDateTime with Laravel, follow these steps:
-
Publish the Configuration File:
Run the following command to publish the package configuration file:
php artisan vendor:publish --provider="BanglaDateTime\Laravel\BanglaDateTimeServiceProvider"This will create a configuration file at
config/bangladatetime.php. -
Configuration:
Edit the
config/bangladatetime.phpfile to set your desired date formats and timezone. -
Usage:
The package integrates with Laravel's
Carbonclass, allowing you to use custom methods to format dates in Bangla format and Bangla calendar directly.
Using with Eloquent Models
If you have a model with a datetime cast, you can easily format the datetime attributes using the BanglaDateTime methods. For example:
use App\Models\User; // Retrieve a user and format the created_at attribute in Bangla format $user = User::find(1); echo $user->created_at->formatBangla('l jS F Y h:i:s'); // Format the created_at attribute in Bangla calendar format echo $user->created_at->toBangla('l jS F Y h:i:s');
Output:
Created at with Bangla format: বৃহস্পতিবার ১২ই সেপ্টেম্বর ২০২৪ ০৩:৩৭:০৩
Created at converted to Bangla: বৃহস্পতিবার ২৮শে ভাদ্র ১৪৩১ ০৩:৩৭:০৩
Basic Example
use Illuminate\Support\Carbon; // Get current date and time in Bangla format echo Carbon::now()->formatBangla('l jS F Y h:i:s'); // Get current date and time in Bangla calendar format echo Carbon::now()->toBangla('l jS F Y h:i:s');
Output:
Current time with Bangla format: বৃহস্পতিবার ১২ই সেপ্টেম্বর ২০২৪ ০৩:৩৭:০৩
Current time converted to Bangla: বৃহস্পতিবার ২৮শে ভাদ্র ১৪৩১ ০৩:৩৭:০৩
Setting a Custom Date
use Illuminate\Support\Carbon; // Set a custom date ('2023-04-13') in Bangla format echo Carbon::create('2023-04-13')->formatBangla('l jS F Y h:i:s'); // Set a custom date ('2023-04-13') in Bangla calendar format echo Carbon::create('2023-04-13')->toBangla('l jS F Y h:i:s');
Output:
Set Time with Bangla format: বৃহস্পতিবার ১৩ই এপ্রিল ২০২৩ ১২:০০:০০
Set Time & converted to Bangla: বৃহস্পতিবার ৩০শে চৈত্র ১৪২৯ ১২:০০:০০
Working with Timezones
use Illuminate\Support\Carbon; // Set current time with a specific timezone ('Asia/Dhaka') in Bangla format echo Carbon::now('Asia/Dhaka')->formatBangla('l jS F Y h:i:s'); // Set current time with a specific timezone ('Asia/Dhaka') in Bangla calendar format echo Carbon::now('Asia/Dhaka')->toBangla('l jS F Y h:i:s');
Output:
Set Time & Time Zone with Bangla format: বৃহস্পতিবার ১২ই সেপ্টেম্বর ২০২৪ ০৯:৩৭:০৩
Set Time & Time Zone & converted to Bangla: বৃহস্পতিবার ২৮শে ভাদ্র ১৪৩১ ০৯:৩৭:০৩
Custom Format and Timezone
You can specify a custom format and timezone when calling formatBangla and toBangla methods:
use Illuminate\Support\Carbon; // Get current date and time in Bangla format with a custom format and timezone echo Carbon::now()->formatBangla('d/m/Y H:i:s', 'Asia/Dhaka'); // Get current date and time in Bangla calendar format with a custom format and timezone echo Carbon::now()->toBangla('d/m/Y H:i:s', 'Asia/Dhaka');
Output:
Custom Time with Bangla format: ১২/০৯/২০২৪ ১৫:৩৭:০৩
Custom Time & converted to Bangla: ২৮/ভাদ্র/১৪৩১ ১৫:৩৭:০৩
API
BanglaDateTime::create($time = 'now', $timezone = 'UTC')
Creates a new BanglaDateTime instance.
$time: The date and time to use (optional, defaults to'now').$timezone: The timezone to use (optional, defaults to'UTC').
format($format)
Formats the date and time using a specified format, with the output in the Bangla locale.
$format: The format string (same as PHP'sDateTime::format).
toBangla($format)
Converts and formats the date and time into the Bangla calendar and Bangla numbers.
$format: The format string (same as PHP'sDateTime::format).
Helper Functions
BanglaDateTime provides the following global helper functions for easy access:
-
bangla_date_time($time = 'now', $timezone = 'UTC'): Creates a newBanglaDateTimeinstance.$date = bangla_date_time('2023-04-13', 'Asia/Dhaka');
-
format_bangla_date($format, $time = 'now', $timezone = 'UTC'): Formats a date/time in Bangla format.echo format_bangla_date('l jS F Y h:i:s');
-
convert_to_bangla_calendar($format, $time = 'now', $timezone = 'UTC'): Converts a date/time to Bangla calendar format.echo convert_to_bangla_calendar('l jS F Y h:i:s');
Contributing
Feel free to contribute by submitting a pull request or opening an issue. Your contributions are highly appreciated!
License
This library is open-sourced software licensed under the MIT license.
bangladatetime/laravel 适用场景与选型建议
bangladatetime/laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 214 次下载、GitHub Stars 达 15, 最近一次更新时间为 2024 年 09 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「datetime」 「Bangla」 「bangladesh」 「Date Conversion」 「Bangla Calendar」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bangladatetime/laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bangladatetime/laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bangladatetime/laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Tools to convert between .NET and PHP date formats
Time provider, providing consistent current date, time, datetime and timezone across the request.
Adds the EDTF data type to Wikibase
Datetime helpers for timezone handling
A Laravel package for converting English numbers into Bangla digits, Bangla words, Bangla month names, and Bangla money format with an easy-to-use API.
Extended DateTime Class For Bangla Date and Time
统计信息
- 总下载量: 214
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-13