英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论