I have a problem with checking if my date in unix is a current date with using dayjs library, I try like below:
const date = 1631978008; //today: 2021-09-18
const isToday = dayjs().isSame(date, 'day'); //return false
but always return me false when my date is a today date, can someone tell me why? it should return true :/
thanks for any help!
You can use the unix function to parse the unix timestamp in seconds before comparing it with the current time.
const date = 1631978008; //today: 2021-09-18
const isToday = dayjs().isSame(dayjs.unix(date), 'day');
console.log(isToday);
<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>