Javascript so sánh hai ngày tháng (đối tượng Date)
Hàm javascript helper (với typescript) ngắn gọn giúp so sánh hai ngày tháng (đối tượng Date) với nhau chỉ với 1 dòng code.
#JavaScript version
// `a` and `b` are `Date` instances
const compare = (a, b) => a.getTime() > b.getTime();
#TypeScript version
const compare = (a: Date, b: Date): boolean => a.getTime() > b.getTime();
#Ví dụ
compare(new Date('2020-03-30'), new Date('2020-01-01')); // true