Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get number of seconds since

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....

like image 614
Job Avatar asked Feb 03 '11 20:02

Job


People also ask

How many seconds has it been since 1970?

1665273605 seconds elapsed since jan 1 1970. It is the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970, minus leap seconds. Every day is treated as if it contains exactly 86400 seconds, so leap seconds are to be subtracted since the Epoch.

How many seconds have passed since the epoch?

So far, 56505605 seconds have passed since the start of 2021. There are 0 seconds remaining. It is currently week number 42 of 2022 . It is day number 290 of 2022.

How do you get epoch time in seconds?

long epoch = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/1970 01:00:00").getTime() / 1000; Timestamp in seconds, remove '/1000' for milliseconds. date +%s -d"Jan 1, 1980 00:00:01" Replace '-d' with '-ud' to input in GMT/UTC time.

How long has it been since epoch?

There are 738824 days between 0000-00-00 and today (Sunday, Oct 30, 2022).


1 Answers

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);
like image 173
David Hedlund Avatar answered Oct 14 '22 19:10

David Hedlund