本文整理汇总了TypeScript中date-fns/esm.format函数的典型用法代码示例。如果您正苦于以下问题:TypeScript format函数的具体用法?TypeScript format怎么用?TypeScript format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了format函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: format
format(date: NgbDateStruct): string {
if (date === null) {
return '';
}
const d = new Date(date.year, date.month - 1, date.day);
return isValid(d) ? format(d, this.dateFormat) : '';
}
示例2: stringify
// Performs pre-processing before stringifying from JSON
private stringify(schedule: ScheduledTransaction): ScheduledTransaction {
// To avoid timezone issue, convert the native JS date back to a string ("YYYY-MM-DD") before saving
const scheduleCopy = angular.copy(schedule);
scheduleCopy.next_due_date = format(scheduleCopy.next_due_date, "YYYY-MM-DD");
return scheduleCopy;
}
示例3: parse
parse(value: string): NgbDateStruct {
if (!value) {
return null;
}
const d = new Date(format(value, this.dateFormat));
return isValid(d) ? { year: d.getFullYear(),
month: d.getMonth() + 1,
day: d.getDate() } : null;
}
示例4: it
it("should convert the next due date from a date to a string", (): void => {
schedule.next_due_date.should.be.a("string");
schedule.next_due_date.should.deep.equal(format(new Date(), "YYYY-MM-DD"));
});
示例5: beforeEach
beforeEach((): ScheduledTransaction => (schedule = scheduleModel["parse"](createScheduledBasicTransaction({next_due_date: format(new Date(), "YYYY-MM-DD HH:mm:ss")}))));
示例6: it
it("should convert the transaction date from a date to a string", (): void => {
(transaction.transaction_date as string).should.be.a("string");
(transaction.transaction_date as string).should.deep.equal(format(new Date(), "YYYY-MM-DD"));
});
示例7: beforeEach
beforeEach((): Transaction => (transaction = transactionModel["parse"](createBasicTransaction({transaction_date: format(new Date(), "YYYY-MM-DD HH:mm:ss")}))));