Need some time functions

  • Thread starter Thread starter Ron Harter
  • Start date Start date
R

Ron Harter

I have inherited a project that where I need to convert time form the
DataTime format to the old form of seconds since 1/1/70. I can't locate any
functionality in the framework (2.0) that even knows about that particular
format.

Can some one point me to some code that does that. I also need to give an
arbitrary date in the future and get time in seconds from the Epoch. I am
hoping to avoid have to write the functionality if some is already out
there.



Thanks in Advance
 
You should just be able to use the DateTime class ...

in order to get a future date ... just take ..

TimeSpan t = YourDate - new DateTime(1970,1,1);
return t.TotalSeconds;

in order to get a date from seconds just use

DateTime YourDate= new DateTime(1970,1,1).AddSeconds(yourseconds);

also remember that seconds since epoch are generally stored in UTC :D

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top