使用模拟的 PHP 方法在 C# 中创建波斯日历






3.28/5 (17投票s)
生成具有模拟 PHP 方法的波斯日历。

引言
我之前已经在使用 PHP 进行编程了;我正在使用以下日期方法:
时间
mktime
date
由于我正在使用 C#,我总是喜欢编写一个包含这些方法的类,因为使用这些方法比 C# 类更容易(在我看来)。最终,我编写了这个类,你可以使用它。你可以像使用 PHP 方法一样使用这个库(time
、mktime
、date
)。
MohammadDayyanCalendar 方法
-
public uint Time()
返回自 Unix 纪元(1970 年 1 月 1 日 00:00:00 GMT)以来,以秒为单位的当前时间。
-
public string Date(string Format, double Seconds, bool persianNumbers)
-
public int Mktime(int year, int month, int day, int hour, int minute, int second)
返回与给定参数对应的 Unix 时间戳。这个时间是一个整数,包含 Unix 纪元(1970 年 1 月 1 日 00:00:00 GMT)和指定时间之间的秒数。
根据给定的格式字符串和给定的 double 秒数,返回一个格式化的 string
。你可以在波斯语文档中查看所有支持的格式。
Using the Code
让我们看看如何使用这个类。
将这个类添加到你的项目引用中

现在我们可以在我们自己的项目中使用了这个 DLL
public Form1()
{
InitializeComponent();
MDCalendar mdCalendar = new MDCalendar();
DateTime date = DateTime.Now;
TimeZone time = TimeZone.CurrentTimeZone;
TimeSpan difference = time.GetUtcOffset(date);
uint currentTime = mdCalendar.Time() + (uint)difference.TotalSeconds;
label1.Text = mdCalendar.Date("W D M Y G .... d E Z A", currentTime, true);
label2.Text = mdCalendar.Date("H : i : s", currentTime, true);
}
尽情享用!
历史
- 2008 年 6 月 14 日:首次发布
- 2008 年 12 月 27 日:最后更新