5 Replies - 1056 Views - Last Post: 09 May 2013 - 03:53 AM Rate Topic: -----

#1 the5thelement  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 56
  • Joined: 30-July 12

UnixTime -> DateTime

Posted 07 May 2013 - 08:06 PM

Hello! I have a quick question. How would I convert an UnixTime to a DateTime?
I am using this code to convert the DateTime to UnixTime and adding 24 hours.
Dim uTime as Integer
uTime = (DateTime.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds + 86400


Is the conversion to DateTime smiler? I have been searching google for over an hour and
cannot seem to find what I am looking for.

Is This A Good Question/Topic? 0
  • +

Replies To: UnixTime -> DateTime

#2 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: UnixTime -> DateTime

Posted 07 May 2013 - 08:41 PM

View Postthe5thelement, on 07 May 2013 - 09:06 PM, said:

Hello! I have a quick question. How would I convert an UnixTime to a DateTime?
I am using this code to convert the DateTime to UnixTime and adding 24 hours.
...
Is the conversion to DateTime smiler? I have been searching google for over an hour and
cannot seem to find what I am looking for.

Is there a reason you want to convert to Unix time and back again? It would be far easier to just use the .Net Date and DateTime classes.
Was This Post Helpful? 0
  • +
  • -

#3 dbasnett  Icon User is offline

  • D.I.C Addict

Reputation: 102
  • View blog
  • Posts: 584
  • Joined: 01-October 08

Re: UnixTime -> DateTime

Posted 08 May 2013 - 03:58 AM

Is the question, "How would I convert an Unix timestamp to a DateTime?"

This post has been edited by dbasnett: 08 May 2013 - 03:58 AM

Was This Post Helpful? 0
  • +
  • -

#4 the5thelement  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 56
  • Joined: 30-July 12

Re: UnixTime -> DateTime

Posted 08 May 2013 - 11:05 AM

View Postlar3ry, on 07 May 2013 - 08:41 PM, said:

Is there a reason you want to convert to Unix time and back again? It would be far easier to just use the .Net Date and DateTime classes.



The reason I am converting to a timestamp is so that my application can lockout a control, until the current timestamp
matches that of the lockout timestamp. I however need to convert the lockout timestamp to datetime so that the user can
visibly see when the lockout will lift. This is part of a game I am creating that allows the user a change to win a prize every 24 hours.

View Postdbasnett, on 08 May 2013 - 03:58 AM, said:

Is the question, "How would I convert an Unix timestamp to a DateTime?"


Yes, that is what I meant sorry for the confusion.

If this doesn't make sense please say so.

This post has been edited by the5thelement: 08 May 2013 - 11:06 AM

Was This Post Helpful? 0
  • +
  • -

#5 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: UnixTime -> DateTime

Posted 08 May 2013 - 05:57 PM

Is this something like what you are looking for?

Make a form with one button , one label, and one timer, and paste this code in.
Option Strict On

Public Class Form1
    Private TimeStamp As DateTime
    Private Remaining As TimeSpan

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        TimeStamp = Now().AddDays(1)
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Remaining = TimeStamp - Now()
        Label1.Text = Remaining.Hours.ToString() & ":" & Remaining.Minutes.ToString & ":" & Remaining.Seconds.ToString
    End Sub
End Class


This post has been edited by lar3ry: 08 May 2013 - 05:58 PM

Was This Post Helpful? 0
  • +
  • -

#6 dbasnett  Icon User is offline

  • D.I.C Addict

Reputation: 102
  • View blog
  • Posts: 584
  • Joined: 01-October 08

Re: UnixTime -> DateTime

Posted 09 May 2013 - 03:53 AM

Try this

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim someUnixTimestamp As Integer = 1100083647
        Dim d As DateTime = TimeStampToDatetime(someUnixTimestamp)
        d = d.AddHours(24)
        Debug.WriteLine(d.ToLongDateString)
    End Sub

    Private Function TimeStampToDatetime(unixTS As Double) As DateTime
        Dim retv As DateTime = #1/1/1970# 'unix timestamps based on this date
        retv = retv.AddSeconds(unixTS)
        Return retv
    End Function


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1