에서 내가 좋아하는 것,이 방법이잘못된 날짜 시간 타이프
private modifyDate(dateString: string): Date {
let formattedDate= new DatePipe(Defaults.APPLICATION_LOCALE).transform(new DateIEPipe().transform(dateString), 'shortDate');
let newFormattedDate: Date = new Date(formattedDate);
return newFormattedDate;
}
입력 등의 날짜를 수정하는 방법이 "2017-01-23T14 : 09 : 19 + 0100"즉, 문자열
에게파이프를 사용하여 시간대가있는 문자열의 서식을 지정하고 있습니다.
@Pipe({
name: 'dateIE'
})
export class DateIEPipe implements PipeTransform {
transform(input:String): any {
if(input.trim() == "") return input;
// Check if timezone present in the date string?
let splits = input.split("+");
let formattedTZ = "";
if(splits.length > 1) {
formattedTZ = splits[1].substr(0, 2).concat(":").concat(splits[1].substr(2));
return splits[0].concat("+").concat(formattedTZ);
} else {
return input;
}
}
}
이 파이프는 23.01.2017 09:19와 같은 날짜 문자열을 반환합니다. 이제 나는 이것을 "Date"로 바꾸고 싶다. "let newFormattedDate : Date = new Date (formattedDate);" 하지만 잘못된 날짜로 표시됩니다. 이 문제를 해결하는 방법?
기본값은 무엇입니까? APPLICATION_LOCALE .. ?? –
@VivekSingh 로케일을 설정하기위한 것이며 기본 로케일을 en_US로 설정했습니다 – Protagonist