Add conversion to DateOnly from DateTime and DateTimeOffset #103440
-
Hi .NET team and community! I found the Here is code snippets: public DateOnly ToDateOnly() =>
DateOnly.FromDateTime(this); public DateOnly ToDateOnly() =>
DateOnly.FromDateTime(_dateTime); Can't create a PR, so unit tests included. [Fact]
public static void ToDateOnly()
{
DateTime dateTime = new DateTime(2024, 06, 13, 11, 55, 45, 0, DateTimeKind.Utc);
Assert.Equal(new DateOnly(2024, 06, 13), dateTime.ToDateOnly());
} [Fact]
public static void ToDateOnly()
{
DateTimeOffset dateTimeOffset = new DateTimeOffset(new DateTime(2024, 06, 13, 11, 55, 45, 0, DateTimeKind.Utc));
Assert.Equal(new DateOnly(2024, 06, 13), dateTimeOffset.ToDateOnly());
} |
Beta Was this translation helpful? Give feedback.
Answered by
huoyaoyuan
Jun 14, 2024
Replies: 2 comments
-
API requests go in the issues section |
Beta Was this translation helpful? Give feedback.
0 replies
-
Duplicate of #58734 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
mkorsukov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Duplicate of #58734