本文介绍了asp.net中的时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个需要时差的项目并输出结果.
例如:如果一个文件在1小时前发布,那么它会在发布时间:1小时前显示.
如果文件在3天前发布,则显示3天前和
如果文件是在几秒钟前发布的,那么它会在不到一分钟前显示.

我认为它现在可以从系统日期计算发布日期.
请帮我怎么做.

在此先感谢

I create a project where i need time difference and output the result.
Ex: If one file is posted 1 hr ago then it show in the Time of post:1hr ago.
If file is posted 3 days ago then it show 3 days ago and
if file is posted just few second ago then it display less than a minute ago.

I think it calculate the posted date from system date now.
Please help how can i do that.

Thanks in advance

推荐答案

System.DateTime previousPost = //...

//...

System.DateTime lastPost = System.DateTime.Now;
System.TimeSpan duration = lastPost - PreviousPost;

//see duration properties to get duration as double or integer, in any units:
int roundedToHours = duration.Hours;
double preciseHours = duration.TotalHours;

//seconds, days, milliseconds, minutes...



-SA



—SA



Firstly, you will be having a date of file posted right? Ex: PostedDate

secondly, you can fetch today's date. using DateTime.Now. Ex: CurrentDate

Finally, Compare it using

TimeSpan t = CurrentDate.Substract(PostedDate);
Now, say

t.Days to get difference

Thanks



希望对您有帮助:)



Hope this will help you :)


这篇关于asp.net中的时差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 11:42