我有一个 ISO 持续时间值,我需要显示“XX 年,XX 个月,XX 天”。我使用它luxon和humanize -duration。Duration.fromISO() 工作正常,但人性化持续时间转换出错。你能帮忙吗?
transform(value: string): string {
console.log(value);
let formattedIso = Duration.fromISO(value);
console.log(humanizeDuration(formattedIso, { language: 'en', units: ["y", "mo", "d"], round: true}));
}
输出:
P1Y11M3D; 1年10个月28天
P2Y1M30D; 2年1个月29天