natilosir/jalali 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

natilosir/jalali

最新稳定版本:1.0.4

Composer 安装命令:

composer require natilosir/jalali

包简介

A simple PHP library for managing Jalali (Shamsi) dates.

README 文档

README

This library helps you convert dates between the Gregorian (Miladi) and Jalali (Persian) calendars in PHP. Below are some examples of how to use the library.

Install

composer require natilosir/Jalali

Alternatively, you can clone the repository directly:

git clone https://github.com/natilosir/Jalali
Use
require __DIR__ . '/vendor/autoload.php';
use natilosir\jalali\time;

Example Usage

  1. Set the Timezone to Tehran
    You can set the timezone to Tehran (UTC+3.5) using the Timezone method.

  2. Convert Timestamp to Jalali Date
    Convert a Unix timestamp to a Jalali date using the toj method.

  3. Modify the Jalali Date
    You can modify a Jalali date by adding hours, days, months, or years using the addH, addD, addM, and addY methods.

  4. Format the Date in Persian
    Use the format method to display the date in Persian format.

  5. Convert Jalali Date to Timestamp
    You can convert a Jalali date string to a Unix timestamp using the tot method.

  6. Convert Jalali Date to Gregorian
    Use the miladi method to convert a Jalali date to its Gregorian counterpart.

Supported Placeholders

Placeholder Description Example
y Last two digits of the Jalali year 03
Y Full Jalali year 1403
m Numeric representation of the Jalali month 09
M Name of the Jalali month (in Persian) آذر
d Numeric representation of the Jalali day 25
D Day suffix (in Persian) بیست‌و‌پنجم
W Day of the week (in Persian) یک‌شنبه
h Hour in 12-hour format 06
H Hour in 24-hour format 18
i Minutes 33
s Seconds 36

Example Usage

// Set timezone offset (e.g., Iran Standard Time)
time::Timezone(3.5);

// Define a Gregorian timestamp
$timestamp = time();

// Format the Jalali date
$formattedDate = time::format($timestamp, 'W D M Y h:i:s');
// OR
$formattedDate = time::format('W D M Y h:i:s');

// Output: یک‌شنبه بیست‌و‌پنجم آذر 1403 06:33:36
echo $formattedDate;

Placeholders in Action

Given:

  • Jalali date: 1403/09/25
  • Gregorian timestamp: 2024-12-15 06:33:36

Using the format string 'W D M Y h:i:s', the replacements are:

$timestamp = strtotime('2024-12-15 06:33:36');
$formattedDate = time::format($timestamp, 'W D M Y h:i:s');
// OR
$formattedDate = time::format('W D M Y h:i:s');

// Output: یک‌شنبه بیست‌و‌پنجم آذر 1403 06:33:36
echo $formattedDate;

Code Example

Set the timezone to Tehran

time::Timezone(3.5); // tehran

Convert timestamp to Jalali date

$timestamp  = time(); 
$jalaliDate = time::toj($timestamp, 'Y/m/d h:i:s');
// OR
$jalaliDate = time::toj('Y/m/d h:i:s');

echo "Jalali Date: {$jalaliDate}\n"; // Jalali Date: 1403/09/24 23:24:01

Modify the Jalali date

$modifiedDate = time::toj($timestamp)->addH(2)->addD(3)->addM(4)->addY(5);
echo "Modified Jalali Date: {$modifiedDate}\n"; // Modified Jalali Date: 1409/01/28 01:24:01

Format the date in Persian

echo time::format($timestamp, 'W D M Y h:i:s'); // Jalali Date: یک‌شنبه بیست‌و‌پنجم آذر 1403 10:25:46

Convert Jalali date to timestamp

$jalaliDateInput    = '1402/09/24 14:30:00';
$convertedTimestamp = time::tot($jalaliDateInput);
echo "Timestamp: $convertedTimestamp\n"; // Timestamp: 1702638000

Convert Jalali date to Gregorian using the miladi method

echo time::miladi('1401/05/24 14:12:32'); // 2022-08-15 10:42:32

统计信息

  • 总下载量: 38
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 4
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固