Date handling using DayJS
const dayjs = require('dayjs');
let today = dayjs()
let otherDay = dayjs('2019-04-22 :43:55')
let format = 'MM/DD/YYYY HH:mm:ss'
if(today.isBefore(otherDay, 'day')){
console.log(today.format(format) + ' is BEFORE ' + otherDay.format(format))
} else if(otherDay.isBefore(today, 'day')){
console.log('Today is AFTER other day')
} else {
console.log('Today is THE SAME as the other day')
}
let day = new Date(1556305077332)
console.log(day)
day = dayjs()
console.log(day.toDate()) // <-- Converts to normal date object
day = new Date(day) // <-- Date can take a dayjs object. It just stores milliseconds past 1970
console.log(day)
console.log(dayjs().startOf('day').toDate())
dayjs().startOf('day').valueOf()
let d = new Date()
d = d.setDate(d.getDate() - 7)
console.log(d)
no comments