My dates come out of the database looking like this: 2013-11-21 17:43:20
I\'m trying to user Angular\'s date filter to turn them into something prettier
I created a pipe for this as follows
import { Pipe } from "@angular/core";
@Pipe({ name: 'DateToIso' }) export class DateToIso {
transform(value, args) {
var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
var parts=value.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
var converted = new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
let newValue = converted.toISOString();
return newValue;
}
}