Solved

Convert Unix epoch timestamp to datetime

Posted on 2008-10-10
1
996 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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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