Solved

Convert Unix epoch timestamp to datetime

Posted on 2008-10-10
1
999 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

759 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