如何更改飛鏢中的日期格式
我得到從和到日期的差異值是 int。如何將此整數更改為日期格式...并將其轉換為 0Days 0Months 7days; 我需要這種格式
但我得到了這種格式, 請參閱車輛時代:
vehicleAge(DateTime doPurchase, DateTime doRenewel) {
age = doPurchase.difference(doRenewel).abs().inDays.toInt();
return age;
}
那是我的功能...
uj5u.com熱心網友回復:
試試這個
vehicleAge(DateTime doPurchase, DateTime doRenewel) {
Duration parse = doPurchase.difference(doRenewel).abs();
return "${parse.inDays~/360} Years ${((parse.inDays%360)~/30)} Month ${(parse.inDays%360)%30} Days";
}
uj5u.com熱心網友回復:
使用此包time_machine并嘗試此代碼
vehicleAge(DateTime doPurchase, DateTime doRenewel) {
LocalDate a = LocalDate.dateTime(doPurchase);
LocalDate b = LocalDate.dateTime(doRenewel);
Period diff = b.periodSince(a);
return "${diff.years} Years ${diff.months} Months ${diff.days} Days";
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/421014.html
標籤:
下一篇:當串列包含特定字串時顯示影像
