반응형
각도 그리드를 사용하여 AM/PM 형식으로 시간 표시
시간을 AM/PM 형식으로 표시하기 위해 startTime 및 endTime이라는 날짜 시간 속성을 가진 엔티티를 수신하는 Angular 그리드를 포맷하려면 어떻게 해야 합니까?현재 사용하고 있는 것은 다음과 같습니다.
{ field: 'StartTime', displayName: 'Start Time', cellFilter: 'date:\'hh:mm tt\''},
{ field: 'EndTime', displayName: 'End Time', cellFilter: 'date:\'hh:mm tt\''},
AM이나 PM 대신 'tt'가 뜨는 게 당연해요.이전에 Angular ngGrid에서 AM/PM을 실행한 적이 있습니까?
간단합니다.이것을 참조해 주세요.
{ field: 'createdOn', displayName: 'Created On', width: '180px',
cellTemplate:
"<div class='ngCellText'>{{row.entity.createdOn | date:'MM/dd/yy h:mm:ss a'}}</div>" },
바로 그겁니다.
그냥 몇 가지 일을 합쳐야 했어.먼저 필터:
app.filter('ampmtime',
function () {
return function (value) {
if (!value) { return ''; }
var hours = new Date(value).getHours();
var minutes = new Date(value).getMinutes();
var ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0' + minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
return strTime;
}
});
다음으로 gridOptions의 함수에 대한 호출을 실시합니다.
{ field: 'StartTime', displayName: 'Start Time', cellFilter: 'ampmtime'},
{field:'EndTime', displayName: 'End Time', cellFilter: 'ampmtime'}
준비 다 됐어
방금 같은 문제가 발생하여 Angular의 날짜 필터를 사용하여 보다 간단한 솔루션을 찾았습니다.그냥 a로 바꾸면 돼
{ field: 'StartTime', displayName: 'Start Time', cellFilter: 'date:\'hh:mm a\''}
날짜 필터에 대한 각도 차이 확인 - https://docs.angularjs.org/api/ng/filter/date
각도 초과 V2용shortTime
와 함께date
파이프:
{{ myDate | date : 'shortTime' }}
'짧은 시간': 'h:mm a'(오전 9:03)와 동일합니다.
언급URL : https://stackoverflow.com/questions/24662511/displaying-time-in-am-pm-format-with-angular-grid
반응형
'source' 카테고리의 다른 글
Golang에서 유형 맵[string] 인터페이스 {}의 중첩된 맵에 액세스하는 중 (0) | 2023.03.25 |
---|---|
'react-redux' 모듈에 대한 선언 파일을 찾을 수 없습니다. (0) | 2023.03.25 |
@Directive vs @Component in Angular (0) | 2023.03.25 |
.env 파일을 선택하지 않고 리액트 앱을 생성하시겠습니까? (0) | 2023.03.25 |
libaio.so.1: 공유 개체 파일을 열 수 없습니다. (0) | 2023.03.25 |