在 .NET BCL 里, DateTime 类型是大家经常使用的类型,它代表了日期时间,Date and Time ,但是一直没有类型可以单独表示日期(Date)或者时间(Time)

在 .NET 6 里,提出了关于此问题的提议 https://github.com/dotnet/runtime/issues/49036 ,增加两个新结构体 DateOnly ,和 TimeOnly ,为什么这么取名,在上面的 issue 和 文末的资料里给出了解释,出于各个方面的考虑。

源码:

TimeOnly: https://github.com/dotnet/runtime/blob/3af186126e7e0ae99f3fb12dec002596548bb62f/src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs

.NET 6 日期和时间结构

DateOnly: https://github.com/dotnet/runtime/blob/3af186126e7e0ae99f3fb12dec002596548bb62f/src/libraries/System.Private.CoreLib/src/System/DateOnly.cs

.NET 6 日期和时间结构

TimeOnly 表示时间,取值范围 00:00:00 至 23:59:59.9999999
DateOnly 表示日期,取值范围 0001年1月1日至9999年12月31日

参考资料

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-09-09
猜你喜欢
  • 2021-07-06
  • 2021-08-10
  • 2022-12-23
  • 2022-12-23
  • 2022-03-01
  • 2022-01-10
相关资源
相似解决方案