Team-ClanX.org Forum Index Team-ClanX.org
Web Board for the ClanX Team
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    Return homeReturn Home 

Converting epoch time into a useable dateTime in C#

 
Post new topic   Reply to topic    Team-ClanX.org Forum Index -> C++/C#
View previous topic :: View next topic  
Author Message
Martyr2
Site Admin


Joined: 10 Jul 2004
Posts: 124
Location: Vancouver

PostPosted: Mon Jul 30, 2007 3:33 pm    Post subject: Converting epoch time into a useable dateTime in C# Reply with quote

Hi guys,

I wrote this quick little function that should help you with converting epoch time (the amount of seconds elapsed since Jan 1, 1970 and used in unix timestamps) into a DateTime object for use with C#.

It is extra special for those applications which connect to IRC servers and have raw numerics that may contain ctime values.

Code:

public string convertEpoch(double timestamp) {

   // First make a System.DateTime equivalent to the UNIX Epoch.
   System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);

   // Add the number of seconds in UNIX timestamp to be converted.
   dateTime = dateTime.AddSeconds(timestamp);
 

   return dateTime.ToString();
}


Enjoy!
_________________
Martyr2
Co-Founder and Webmaster
Team-ClanX Scripters
Email: martyr2@team-clanx [dot] org
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Team-ClanX.org Forum Index -> C++/C# All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group