bangladatetime/php
Composer 安装命令:
composer require bangladatetime/php
包简介
A PHP library to convert DateTime to Bangla format and Bangla calendar.
README 文档
README
BanglaDateTime is a PHP library 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/php
Usage
To use BanglaDateTime, you can create a new instance of the date and time with either the current time, a specific date, or a specific timezone.
Basic Example
use BanglaDateTime\BanglaDateTime; require __DIR__ . '/vendor/autoload.php'; // Create a BanglaDateTime instance with the current date and time, formatted in Bangla locale $date = BanglaDateTime::create(); echo 'Current time with Bangla format: ' . $date->format('l jS F Y h:i:s'); echo '<br>'; // Create a BanglaDateTime instance with the current date and time, converted to the Bangla calendar $date = BanglaDateTime::create(); echo 'Current time converted to Bangla: ' . $date->toBangla('l jS F Y h:i:s');
Output:
Current time with Bangla format: বৃহস্পতিবার ১২ই সেপ্টেম্বর ২০২৪ ০৩:৩৭:০৩
Current time converted to Bangla: বৃহস্পতিবার ২৮শে ভাদ্র ১৪৩১ ০৩:৩৭:০৩
Setting a Custom Date
You can also specify a custom date when creating the BanglaDateTime instance:
// Create a BanglaDateTime instance with a custom date ('2023-04-13'), formatted in Bangla locale $date = BanglaDateTime::create('2023-04-13'); echo 'Set Time with Bangla format: ' . $date->format('l jS F Y h:i:s'); echo '<br>'; // Create a BanglaDateTime instance with a custom date ('2023-04-13'), converted to the Bangla calendar $date = BanglaDateTime::create('2023-04-13'); echo 'Set Time & converted to Bangla: ' . $date->toBangla('l jS F Y h:i:s');
Output:
Set Time with Bangla format: বৃহস্পতিবার ১৩ই এপ্রিল ২০২৩ ১২:০০:০০
Set Time & converted to Bangla: বৃহস্পতিবার ৩০শে চৈত্র ১৪২৯ ১২:০০:০০
Working with Timezones
You can also pass a timezone when creating the BanglaDateTime instance:
// Create a BanglaDateTime instance with the current time and a specific timezone ('Asia/Dhaka'), formatted in Bangla locale $date = BanglaDateTime::create('now', 'Asia/Dhaka'); echo 'Set Time & Time Zone with Bangla format: ' . $date->format('l jS F Y h:i:s'); echo '<br>'; // Create a BanglaDateTime instance with the current time and a specific timezone ('Asia/Dhaka'), converted to the Bangla calendar $date = BanglaDateTime::create('now', 'Asia/Dhaka'); echo 'Set Time & Time Zone & converted to Bangla: ' . $date->toBangla('l jS F Y h:i:s');
Output:
Set Time & Time Zone with Bangla format: বৃহস্পতিবার ১২ই সেপ্টেম্বর ২০২৪ ০৯:৩৭:০৩
Set Time & Time Zone & 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/php 适用场景与选型建议
bangladatetime/php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 376 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 09 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「datetime」 「Bangla」 「bangladesh」 「Date Conversion」 「Bangla Calendar」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bangladatetime/php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bangladatetime/php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bangladatetime/php 相关的其它包
同方向 / 同关键字的高下载量 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
统计信息
- 总下载量: 376
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 24
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-13