Flutter:找出两个日期之间的差异 [英] Flutter: Finding Difference Between Two Dates
问题描述
我目前有一个用户的个人资料页面,其中显示了他们的出生日期和其他详细信息。但是我打算通过计算今天的日期和从用户那里获得的出生日期之间的差来找到他们生日前的日子。
I currently have a user's profile page that brings out their date of birth and other details. But I am planning to find the days before their birthday by calculating the difference between today's date and the date of birth obtained from the user.
用户的出生日期
这是今天获得的日期通过使用 intl软件包。
And this is the today's date obtained by using the intl package .
今天的日期
I/flutter ( 5557): 09-10-2018
我现在面临的问题是计算这两个日期的天数差异?
The problem I am facing now is, How do i calculate the difference in days of these two dates?
是否有任何特定的公式或软件包可供我签出?
Are there any specific formula or packages that are available for me to check out?
推荐答案
您可以使用 DateTime
类提供的差异
方法
You can use the difference
method provide by DateTime
class
//the birthday's date
final birthday = DateTime(1967, 10, 12);
final date2 = DateTime.now();
final difference = date2.difference(birthday).inDays;
这篇关于Flutter:找出两个日期之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!