Ooooo boi! Did I just find something cool? Yes indeedy I did! If messing with dates in JavaScript gives you headaches like it does me, check out this library of absolute awesomeness:
Date-Fns – https://date-fns.org/
With gems such as startOfHour(.), isToday(.)/isTomorrow(.), nextWednesday(.), isThisWeek(.), and many more, all the pain and suffering are taken out when messing with dates. Plus, you only import what you need, so it’s a lightweight library too.
Try it out!
Install: npm install date-fns
Import: import isThisWeek from 'date-fns/isThisWeek';
Use: console.log("Is today this week? " + isThisWeek(new Date()));
Have fun! π
You may also be interested in: this JavaScript tutorial
0 Comments