本文整理汇总了TypeScript中date-fns/format.format函数的典型用法代码示例。如果您正苦于以下问题:TypeScript format函数的具体用法?TypeScript format怎么用?TypeScript format使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了format函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: tap
tap(() => {
if (app.application.status && app.application.status.dataPreviewEndpoint && app.mostRecentData) {
const defaultUntil = parse(app.mostRecentData);
const defaultSince = subMonths(startOfDay(defaultUntil), 1);
this.dataPreview$ = this.hatAppSvc.getApplicationData(
app.application.status.dataPreviewEndpoint,
format(defaultSince, 'X'),
format(defaultUntil, 'X')
);
} else {
this.dataPreview$ = of([]);
}
}),
示例2: function
return function(day: Date): VNode {
const dayEnd = addDays(day, 1);
const tours = ctrl.data.tournaments.filter(t =>
t.bounds.start < dayEnd && t.bounds.end > day
);
return h('day', [
h('date', {
attrs: {
title: format(day, 'dddd, DD/MM/YYYY')
}
}, [format(day, 'DD/MM')]),
h('lanes', makeLanes(tours).map(l => renderLane(ctrl, l, day)))
]);
};
示例3: transform
transform(
value: Date | string | number,
formatString: string = 'YYYY-MM-DD HH:mm',
): string {
if (value) {
if (formatString === 'fn') {
return distanceInWordsToNow(value, {
locale: (window as any).__locale__,
});
}
return format(value, formatString);
} else {
return '';
}
}
示例4: ngAfterViewInit
ngAfterViewInit() {
const today = format(new Date(), 'ddd DD MMM YYYY');
this.dateSeparators.changes.pipe(take(1)).subscribe((changes) => {
const todayElement = changes.find(item => {
return item.nativeElement.textContent === today;
});
// TODO: Fix this hack. Material mat-sidenav component does not currently support programmatic scrolling
// See https://github.com/angular/material2/issues/4280
if (todayElement) {
document.querySelector('.mat-sidenav-content').scrollTop = todayElement.nativeElement.offsetTop;
}
});
}
示例5: async
export const getCourses = async (
restaurantId: number,
day: Date,
lang: Lang
): Promise<CourseType[]> => {
const restaurant = await http.get(
`/restaurants/${restaurantId}/menu?day=${format(
day,
'YYYY-MM-DD'
)}&lang=${lang}`
);
if (!restaurant.menus.length) {
return [];
} else {
return restaurant.menus[0].courses;
}
};
示例6: renderTournament
function renderTournament(ctrl: Ctrl, tour: Tournament, day: Date) {
const paddingLeft = 0;
let left = (getHours(tour.bounds.start) + getMinutes(tour.bounds.start) / 60) / 24 * 100;
if (tour.bounds.start < day) left -= 100;
const width = tour.minutes / 60 / 24 * 100;
return h('a.tournament', {
class: tournamentClass(tour, day),
attrs: {
href: '/tournament/' + tour.id,
style: 'width: ' + width + '%; left: ' + left + '%',
title: `${tour.fullName} - ${format(tour.bounds.start, 'dddd, DD/MM/YYYY HH:mm')}`
}
}, [
h('span.icon', tour.perf ? {
attrs: {
'data-icon': iconOf(tour, tour.perf.icon)
}
} : {}),
h('span.body', [ tour.fullName ])
]);
}
示例7: format
import * as format from 'date-fns/format'
const result = format('2017-01-25T21:28:15.000Z', 'DD.MM.YYYY HH:mm:ss')
console.log(result === '25.01.2017 21:28:15')
示例8: transform
transform(date: string | number | Date, to: string = 'YYYY-MM-DDTHH:mm:ssZ'): string {
const nativeDate = parse(date);
return format(nativeDate, to);
}
示例9: format
.map(day => format(day, 'YYYY-MM-DD'))
示例10: it
it('should be now when a bad date', () => {
const ret = getTimeDistance('-today', -NaN);
expect(ret.length).toBe(2);
expect(format(ret[0], FORMAT)).toBe(format(new Date(), FORMAT));
expect(format(ret[1], FORMAT)).toBe(format(new Date(), FORMAT));
});