Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seconds since 1.1.1970 to DateTime 1

Status
Not open for further replies.

juhaka

Programmer
Nov 14, 2002
26
FI
Hi!

My program gets a timestamp (4 byte integer), which is seconds since 1.1.1970 00:00 UTC. What is the easiest way to convert the timestamp to DateTime -object? There must be some ready method for it!? But I haven't found any :O(...
Or must I do a DateTime -object for base time (1.1.1970) and add the seconds to it?

br. Juha Ka
 
Juha -

That's what I would do - start with your Epoch date and add that many seconds.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
DIV and MOD methods would no doubt come in useful here. i don't think they're included with the standared api, and i know they're not included within Math (unless they're hidden by another name). i would probably write these methods first.

____________________________________________________
If you like a post, show you care by giving it a star.
 
seanbo -

No need - the DateTime structure already has a method for that:
Code:
DateTime dtEpochDate = new DateTime(1970, 1, 1);
DateTime dtSomeDate = dtEpochDate.AddSeconds(SecondsSinceEpoch);

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Thanks,Chiph

I just found the same way to do it, but thanks anyway for your time!

br. Juha Ka
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top