Loading

.NET 6 日期和时间结构

在 .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

image

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

image

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

参考资料

posted @ 2021-05-19 09:58  晓晨Master  阅读(1008)  评论(1编辑  收藏  举报