Convert Unix Epoch Time to Seconds in SQL or .NET
First let me thank you all for your help.
What I need is a function that takes in a EPOCH time stamp, like 1452.235687 and converts it to a readable timestamp like '01-01-1970 00:00:00'. More spec开发者_开发问答ifically I only need the time not the date.
If at all possible I would prefer a .NET function instead of a SQL stored procedure. However an SQL stored procedure would work fine as well.
Thank you again,
double EpochSeconds = 1272672608.55;
DateTime time = new DateTime(1970, 1, 1).AddSeconds(EpochSeconds);
Console.WriteLine(time);
Prints out:
5/1/2010 12:10:08 AM
If you just want the time, you can use time.TimeOfDay
.
You can create a DateTime object with the UNIX epoch (1970-01-01) and use the AddSeconds
method.
PowerShell demo:
PS Home:> $e = [datetime]"1970-01-01"
PS Home:> $e.AddSeconds(1452.235687).TimeOfDay
Days : 0
Hours : 0
Minutes : 24
Seconds : 12
Milliseconds : 236
Ticks : 14522360000
TotalDays : 0,016808287037037
TotalHours : 0,403398888888889
TotalMinutes : 24,2039333333333
TotalSeconds : 1452,236
TotalMilliseconds : 1452236
精彩评论