Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert Unix epoch timestamp to datetime

Posted on 2008-10-10
1
Medium Priority
?
1,008 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 2000 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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

715 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