t0n
Version:
Collection of elegant typescript resources for web artisans
15 lines (13 loc) • 590 B
text/typescript
const getFullYear = Date.prototype.getFullYear
const getMonth = Date.prototype.getMonth
const getDate = Date.prototype.getDate
const getHours = Date.prototype.getHours
const getMinutes = Date.prototype.getMinutes
const getSeconds = Date.prototype.getSeconds
const pad = (n: number) => n > 9 ? n : '0' + n
export class Datte {
static dateTime(date: Date = new Date()) {
return getFullYear.call(date) + '-' + pad(getMonth.call(date) + 1) + '-' + pad(getDate.call(date))
+ ' ' + pad(getHours.call(date)) + ':' + pad(getMinutes.call(date)) + ':' + pad(getSeconds.call(date))
}
}