Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在两个波斯日期之间检查波斯日期?_C#_Date_Farsi - Fatal编程技术网

C# 如何在两个波斯日期之间检查波斯日期?

C# 如何在两个波斯日期之间检查波斯日期?,c#,date,farsi,C#,Date,Farsi,我的波斯语日期格式可以采用以下格式之一:mm/YYYY或YYYY/mm 没有日期信息,只有年份和月份。 我想检查两个波斯日期之间的波斯日期: 例如,1400/01介于1399/07和1400/03之间 在日期信息不可用的情况下如何执行此操作?公共静态日期时间GetDate(字符串初始值) public static DateTime GetDate(string initialValue) { int pos = initialValue.IndexOf("/

我的波斯语日期格式可以采用以下格式之一:mm/YYYY或YYYY/mm 没有日期信息,只有年份和月份。 我想检查两个波斯日期之间的波斯日期: 例如,1400/01介于1399/07和1400/03之间 在日期信息不可用的情况下如何执行此操作?

公共静态日期时间GetDate(字符串初始值)
 public static DateTime GetDate(string initialValue)
    {
        int pos = initialValue.IndexOf("/");
        string dformat = pos == 2 ? "MM/yyyy" : "yyyy/MM";
        DateTime dDate = DateTime.MinValue;
        DateTime.TryParseExact(initialValue, dformat, CultureInfo.GetCultureInfo("fa-IR"), DateTimeStyles.None, out dDate);
        return dDate;
    }
    static void Main(string[] args)
    {
        string one = "1399/07";
        string two = "03/1400";
        string three = "01/1400";
        DateTime dOne = GetDate(one);
        DateTime dTwo = GetDate(two);
        DateTime dThree = GetDate(three);
        bool answer = dThree >= dOne && dThree <= dTwo;
        Console.WriteLine($"'{dThree.ToString("yyyy-MM-dd")}' is between '{dOne.ToString("yyyy-MM-dd")}' and '{dTwo.ToString("yyyy-MM-dd")}'? => {answer}");
        Console.ReadKey();
    }
{ int pos=initialValue.IndexOf(“/”); 字符串dformat=pos==2?“MM/yyyy”:“yyy/MM”; DateTime dDate=DateTime.MinValue; DateTime.TryParseExact(initialValue、dformat、CultureInfo.GetCultureInfo(“fa-IR”)、DateTimeStyles.None、out-dDate); 返回dDate; } 静态void Main(字符串[]参数) { 字符串一=“1399/07”; 字符串二=“03/1400”; 字符串三=“01/1400”; DateTime dOne=GetDate(一个); DateTime dTwo=GetDate(两个); DateTime dThree=GetDate(三); bool answer=dThree>=dOne&&dThree