指定された日付の時間部分をチェックしてそれに応じて表示するフィルタを作成できます。私はnative Javascript Dateメソッドを使ってこれを作った。 JS
.filter('timeCheck', function($filter) {
return function (dateString) {
let userDate = new Date(dateString);
let UTCMinutes = userDate.getUTCMinutes();
let UTCHours = userDate.getUTCHours();
if(UTCMinutes === 0 && UTCHours === 0) {
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
let dateWithoutTime = userDate.toLocaleDateString('en-us', options);
return dateWithoutTime;
} else {
const full_options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric' };
let dateWithTime = userDate.toLocaleDateString('en-us', full_options);
return dateWithTime;
}
};
});
で
HTML
で
{{ vm.giveDate | timeCheck }}
ここworking DEMO
私の提案はmoment.jsを使用することです。
カスタムパイプを作成して、入力文字列の時刻部分がゼロでないかどうかをチェックし、datePipeトランスフォームを 'EEEE、MMMM dd、yyyy、h:mm a '形式で使用すると、otherwizeは' EEEE 、MMMM dd、yyyy'をパターンとして出力する。 – mok
@mokサンプルを提供できますか? –
@mok –