Skip to content

Instantly share code, notes, and snippets.

View yankyaw-moe's full-sized avatar
🏠
Working from home

Yan Kyaw Moe yankyaw-moe

🏠
Working from home
View GitHub Profile
@yankyaw-moe
yankyaw-moe / js-date-notes
Created February 1, 2022 14:16
JS Date with native and momentjs
##Moment JS
console.log('current year ', moment().year()); // 2022
console.log('current year ', moment().year(Number)); // Moment<2022-02-01T20:33:23+06:30>
console.log('last year ', moment().subtract(1, 'year').year()); // 2021
console.log('last year ', moment().subtract(1, 'year').year(Number)); // Moment<2021-02-01T20:33:23+06:30>
console.log('current month ', moment().month()); // 1 (20220201)
console.log('last month ', moment().subtract(1, 'month').month()); // 0 (for january)
console.log('current date ', moment().date()); // 1