I find myself with the following, I have to format some dates and I always used the moments. Now I have this dilemma:
var date2 = new Date(year, 6, 0);
var dateEnd = formatShortDate(date2.toString());
and the method formatShortDate
, which is the following:
export function formatShortDate(date: string, originalFormat: string = "", finalFormat: string = "DD/MM/YYYY"): string {
var possibleInputFormats = [
'YYYY-MM-DD[T]HH:mm:ss',
'DD/MM/YYYY',
'DD/MM/YYYY HH:mm:ss.mmm',
'MMMM Do YYYY, H:m:s a',
'x',
'DDMMYYYY',
'YYYY-MM-DDTHH:mm:ss',
]
if (date) {
var momentObj = moment(date, possibleInputFormats);
if (!momentObj.isValid()) {
momentObj = getMomentValid(date);
}
return momentObj.format(finalFormat);
}
else {
return '';
}
This always returns on 30/1/2017, why could it be?