Closed Nabeeh-AlSawaf closed 3 years ago
the following fixed the problem for me
in html
<countdown [config]="{ stopTime: 1614600000000 ,format: 'DD:HH:mm:ss' ,formatDate : formatDate}"></countdown>
in script
CountdownTimeUnits: Array<[string, number]> = [
['Y', 1000 60 60 24 365], // years
['M', 1000 60 60 24 30], // months
['D', 1000 60 60 24], // days
['H', 1000 60 60], // hours
['m', 1000 60], // minutes
['s', 1000], // seconds
['S', 1] // million seconds
];
formatDate?: CountdownFormatFn = ({ date, formatStr, timezone }) => {
let duration = Number(date || 0);
return this.CountdownTimeUnits.reduce((current, [name, unit]) => {
if (current.indexOf(name) !== -1) {
const v = Math.floor(duration / unit);
duration -= v * unit;
return current.replace(new RegExp(${name}+
, 'g'), (match: string) => {
return v.toString().padStart(match.length, '0');
});
}
return current;
}, formatStr);
};
Bug Report or Feature Request (mark with an
x
)Current behavior
when given unix timestamp (1614600000000) and format like 'yyyy-MM-dd E HH:mm:ss a' it gives 1970-01 ..etc example : <countdown [config]="{ stopTime: 1614600000000 ,format: 'yyyy-MM-dd E HH:mm:ss a' }">
Expected behavior
to be correct date of the year month and day 2021 - 03 - 01 14:00:00
Environment