Solved

Convert Unix epoch timestamp to datetime

Posted on 2008-10-10
1
992 Views
Last Modified: 2013-12-17
The title says it all. I have a db with Unix epoch times and I want to convert those to standard datetime's in asp.net.
0
Comment
Question by:johnywhite
1 Comment
 
LVL 8

Accepted Solution

by:
rlh68 earned 500 total points
ID: 22691309
   Public Shared Function ConvertFromUnixTimestamp(ByVal ts As TimeSpan) As Date
        Dim unixDayZero As New TimeSpan(New Date(1970, 1, 1, 0, 0, 0).ToLocalTime.Ticks)
        Return New Date(unixDayZero.Ticks + ts.Ticks)
    End Function

    Public Shared Function ConvertToUnixTimestamp(ByVal d As Date) As Double
        Dim ts As TimeSpan = d.Subtract(New Date(1970, 1, 1, 0, 0, 0, 0).ToLocalTime)
        Return CType(ts.TotalSeconds, Double)
    End Function
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem with Filesystemobject or .NET version 3 34
vb.net checkbox 7 41
Runtime Error 2 28
Help with C#, MVC, razor. 6 23
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now