Donate

How To Convert Epoch Time To DateTime In C#

Good morning awesome programmers,
Me and my fellow teammate encountered a scenario to convert epoch time to datetime. The solution can be found in stack overflow.
private void Form1_Load(object sender, EventArgs e)  
{  
     //long tms = 1308139229;  
     long tms = 1308143650;  
     DateTime dt = FromUnixTime(tms);  
     MessageBox.Show(dt.ToShortDateString());  
} 
 
public DateTime FromUnixTime(long unixTime)  
{  
   var epoch = new DateTime(1970, 1, 1, 0, 0, 0, 
         DateTimeKind.Utc);  
   return epoch.AddSeconds(unixTime);  
}  

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.