54

System.globalization.PersianCalendar を使用してペルシャの日付をグレゴリオの日付に変換するにはどうすればよいですか? ペルシャの日付 (たとえば、今日は 1391/04/07) を変換し、この場合 06/27/2012 になるグレゴリオ暦の日付の結果を取得したいことに注意してください。私は答えのために秒を数えています...

4

6 に答える 6

98

実際には非常に簡単です:

// I'm assuming that 1391 is the year, 4 is the month and 7 is the day
DateTime dt = new DateTime(1391, 4, 7, persianCalendar);
// Now use DateTime, which is always in the Gregorian calendar

DateTimeコンストラクターを呼び出してa を渡すとCalendar、それが変換されますdt.Year。この場合は 2012 になります。逆に行きたい場合は、適切なものを作成してDateTimeから使用する必要がありますCalendar.GetYear(DateTime)

短いが完全なプログラム:

using System;
using System.Globalization;

class Test
{
    static void Main()
    {
        PersianCalendar pc = new PersianCalendar();
        DateTime dt = new DateTime(1391, 4, 7, pc);
        Console.WriteLine(dt.ToString(CultureInfo.InvariantCulture));
    }
}

これは 06/27/2012 00:00:00 を出力します。

于 2012-06-27T08:44:15.730 に答える
0

タグ ビルダー c# を使用して html ヘルパーとしてペルシャのカレンダーを作成し、選択したペルシャの日付をグレゴリオの日付に変換します

https://github.com/tarqawwad/Persian-Calendarにアクセスしてください

ここをクリックして例を表示

于 2022-02-07T06:39:54.190 に答える