In C#, typically you can use DateTime.Today
to get today's date disregarding the time component (e.g. the time component would be at midnight basically).
How do I do that using Luxom library?
I understand you can write DateTime.local()
to get a Date object with current Time included, but is there no simple way to effectively disregard the time component so that I can perform a comparison with another Date object?
I can't find any relevant information in the Luxon documentation, though I may have missed something.
In standard JS, this would do it:
new Date(new Date().setHours(0,0,0,0));
But that seems awkward?
You can startOf('day')
to set midnight to given DateTime
:
"Set" this DateTime to the beginning of a unit of time.
then you can use toJSDate()
to get the equivalent Javascript Date or other method like toISO
, toISODate()
, toFormat()
etc to get the string representation of a DateTime
.
Example:
const DateTime = luxon.DateTime;
console.log( DateTime.local().startOf('day').toJSDate() );
<script src="https://cdn.jsdelivr.net/npm/luxon@1.25.0/build/global/luxon.js"></script>
If you need to compare Luxon objects have a look at Comparing DateTimes section of the manual.