Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am developing Question Forum like this Quick Answers site. I want to

calculate the time difference between the Present Time to Question Posted

Time as follows:

Posted on: 1 hour 44 Sec ago


Please give me idea on how to do this.



Thanks in Advance.


Regards,

Prasad Reddy. M
Posted
Updated 20-Apr-10 22:30pm
v2

The .NET framework gently provides you the TimeSpan struct [^].
:)
 
Share this answer
 
you can use TimeSpan

here is one example of it

public string getFormattedTimeFromSecond(double second)
    {

        TimeSpan t = TimeSpan.FromSeconds(second);

        string formatedTime = string.Format("{0:D2}H:{1:D2}M:{2:D2}S",
                                t.Hours,
                                t.Minutes,
                                t.Seconds);

        return formatedTime;
}
 
Share this answer
 
Hi,

you can use the following code:

DateTime currentDate = DateTime.Now;
DateTime postedDate = DateTime.Now.AddHours(-2);
TimeSpan ts = postedDate.Subtract (currentDate);


then you can use the TimeSpan to display the text you want;

Regards,
Jamil
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900