Get number of seconds since

Job picture Job · Feb 3, 2011 · Viewed 23.2k times · Source

I am writing an application in C#, and I would love to know how you can get the number of seconds in each month. For example, today, February the 3th, I would love to have:

January: 2678400
February: 264000

Basically, I would love to know how many seconds in the past months and how many seconds in the current month at the current time (how many seconds so far).

Any code snippets would be appreciated....

Answer

David Hedlund picture David Hedlund · Feb 3, 2011

Subtracting one date from another will always give you a TimeSpan of the difference:

TimeSpan diff = (new DateTime(2011, 02, 10) - new DateTime(2011, 02, 01));

Console.WriteLine(diff.TotalSeconds);