Well, I'm not sure why this is not in the API. Perhaps John Skeet can answer this question.
I see nothing wrong with the way you did in your second example, but you can calculate tickOfMillisecond as follows:
public static LocalDateTime At(this LocalDate localDate, LocalTime localTime) { var tickOfMillisecond = localTime.TickOfSecond - localTime.Millisecond * 10000; return new LocalDateTime(localDate.Year, localDate.Month, localDate.Day, localTime.Hour, localTime.Minute, localTime.Second, localTime.Millisecond, tickOfMillisecond); }
Personally, I think LocalDateTime should be a constructor for LocalDateTime , so you can do this instead:
var ldt = new LocalDateTime(localDate, localTime);
One more thing - perhaps your extension method should check the date and time as in the same calendar system, and then pass this through the result? I have never used a calendar other than ISO, so I'm not sure about that.
source share