DateOnly.ParseExact 解析不正确

huangapple go评论73阅读模式
英文:

DateOnly.ParseExact incorrect parsing

问题

"DateOnly.ParseExact" 存在缺陷。请参考以下示例。所有输出的日期应该相同。

namespace IssueRep1
{
    internal class Program
    {
        static void Main(string[] args)
        { 
            string[] formats = { "dd/mm/yyyy" };
            string format = formats[0];
            string _strDate = "01/08/2014";
            DateOnly _do1 = DateOnly.ParseExact(_strDate, formats);
            DateOnly _do2 = DateOnly.ParseExact(_strDate, format);
            Console.WriteLine($"{_strDate}, {_do1} {_do2}");
        }
    }
}

输出结果:
01/08/2014, 01-01-2014 01-01-2014

我期望所有日期都相等。八月份被转换为一月份。请确认一下是否存在 Bug,或者是否我理解有误?如何在 dotnet 库中提交 Bug 报告?

英文:

I believe there is a flaw in DateOnly.ParseExact. Refer following example. All the output dates should be same.

namespace IssueRep1
{
    internal class Program
    {
        static void Main(string[] args)
        { string[] formats = { "dd/mm/yyyy" };
            string format = formats[0];
            string _strDate = "01/08/2014";
            DateOnly _do1 = DateOnly.ParseExact(_strDate, formats);
            DateOnly _do2 = DateOnly.ParseExact(_strDate, format);
            Console.WriteLine($"{_strDate}, {_do1} {_do2}");
        }
    }
}

output
01/08/2014, 01-01-2014 01-01-2014

I expected all dates to be equal. August month is being converted to Jan. Can you please confirm if it is a bug or something is wrong with my understanding? How can I file a bug report in dotnet library?

答案1

得分: 4

你应该使用的是

string[] formats = { "dd/MM/yyyy" };

月份的格式是 MM 而不是 mm,小写的 m 表示分钟,这是 datetime 的格式 参考链接

英文:

What you should use is

string[] formats = { "dd/MM/yyyy" };

The format of month is MM not mm the lower case m is for minute and this is the datetime format reference

huangapple
  • 本文由 发表于 2023年1月9日 12:25:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75053173.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定