mdehoog / Semantic-UI-Calendar

Calendar module for Semantic UI
MIT License
805 stars 127 forks source link

Parse date to yyyy-mm-dd #44

Closed wojcikm closed 7 years ago

wojcikm commented 7 years ago

Hello everyone, I couldn't found any information there, also #31 does not work for me (it gives me back an divs element instead of a string). I want to get a date in format yyyy-mm-dd. Still believe there is a single-line solution for this.

wojcikm commented 7 years ago

I'm blind. Found it in the examples link eventually.

formatter: { date: function (date, settings) { if (!date) return ''; var day = date.getDate(); var month = date.getMonth() + 1; var year = date.getFullYear(); return year + '-' + month + '-' + day; } }

gildniy commented 6 years ago

Also with this method can be used for "YYYY/MM/DD" format:

private formatDate(date: Date): string { if (!date) return ''; let day = date.getDate() + '', month = (date.getMonth() + 1) + '', year = date.getFullYear(); if (day.length < 2) day = '0' + day; if (month.length < 2) month = '0' + month; return year + '/' + month + '/' + day; }