Solved

Convert Unix epoch timestamp to datetime

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

8 Experts available now in Live!

Get 1:1 Help Now