日期差异代码 [英] code for date difference
本文介绍了日期差异代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何做日期差异,例如2天前,1小时前,
你能指导我怎么做这个功能吗?
你能不能请发一个代码吗?
先谢谢
解决方案
参考:
1. 如何计算 - 日期时间差异在java中 [ ^ ]
2. android-java-date-difference-in-days [ ^ ]
查看此
DateTime [] dd = new DateTime [] { new DateTime( 2014 , 01 , 10 , 10 , 15 , 01 ), new DateTime( 2014 , 01 , 10 , 10 , 10 , 10 )};
int x = Convert.ToInt32((dd [ 0 ] - dd [ 1 ])。TotalMinutes);
字符串 unit = 天跨度>;
if (x / 60 == 0 )
{
unit = minutes;
}
其他 如果(x / 60 / 24 == 0 )
{
unit = hours;
x = x / 60 ;
}
其他
{
x = x /( 60 * 24 );
}
Console.WriteLine(x + +单元);
How can i do date difference like for eg 2 days ago, 1 hour ago,
Can you please guide me how to do this function?
Can you please post a code of it ?
Thanks in Advance
解决方案
Refer:
1. how-to-calculate-date-time-difference-in-java[^]
2. android-java-date-difference-in-days[^]
Check this
DateTime[] dd = new DateTime[] { new DateTime(2014, 01, 10, 10, 15, 01),new DateTime(2014, 01, 10, 10, 10, 10) }; int x = Convert.ToInt32((dd[0] - dd[1]).TotalMinutes); String unit = "days"; if (x / 60 == 0) { unit = "minutes"; } else if (x / 60 / 24 == 0) { unit = "hours"; x = x / 60; } else { x = x / (60 * 24); } Console.WriteLine(x + " " + unit);
这篇关于日期差异代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文