[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1252
  • Last Modified:

How do you convert an epoch time to a standard Date/Time (m/d/y hh:mm:ss) format?

I am in the process of writing a parsing utility that will take the data from our AVL system and populate it into an SQL database.  However, the one hang up that I am running into is that it stores the date and time in an epoch date format.  I have read this posting:

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22100727.html

but I need it to go the other way.

How would I accomplish this?

Any help would be appreciated.  Thanks.
0
eric_krum
Asked:
eric_krum
  • 3
1 Solution
 
armoghanCommented:
Dim dtr As Date = dtEpoch.AddSeconds(1165449600)
        MsgBox("Windows Time: " + dtDate.ToString)
0
 
armoghanCommented:
and to format
MsgBox("Windows Time: " + dtr.ToString("M/d/y hh:mm:ss", (New Globalization.CultureInfo("en-US")).DateTimeFormat))
0
 
eric_krumAuthor Commented:
I have taken the code that you supplied and modified it as follows:

Dim dtEpoch As Date

        Dim dtr As Date = dtEpoch.AddSeconds(1195369198)
        MsgBox("Windows Time: " + dtr.ToString)
        MsgBox("Windows Time: " + dtr.ToString("M/d/y hh:mm:ss", (New Globalization.CultureInfo("en-US")).DateTimeFormat))

However, the output has the correct M/D but the year and the time are off.  Am I missing something?
0
 
armoghanCommented:
Following would be Complete code.
as 1165449600 stands for 12/07/2006 so time would be 12:00:00 AM
  Dim dtEpoch As Date = "1/1/1970"
     Dim dtr As Date = dtEpoch.AddSeconds(1165449600)
        MsgBox("Windows Time: " + dtr.ToString("MM/dd/yyyy hh:mm:ss tt", (New Globalization.CultureInfo("en-US")).DateTimeFormat))
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now