Solved

function to convert UNIX time to human time in .net

Posted on 2014-04-10
8
481 Views
Last Modified: 2014-06-02
Hello,

i have looked all over the next for a converter for my unix time and i get arithmetic errors over and over can someone help me with this.

 MsgBox(DateAdd("s", CDbl(ModifiedDate), "01/01/1970 00:00:00"))
0
Comment
Question by:Chris Jones
[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
  • 4
  • 4
8 Comments
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 39993468
0
 
LVL 1

Author Comment

by:Chris Jones
ID: 39993856
Yes I have reviewed and tried both links and I get the similar error.
0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 39993862
what kind of error have you got?

Please post error message which will help our experts review and suggest ..!!
0
Technology Partners: 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!

 
LVL 1

Author Comment

by:Chris Jones
ID: 39993929
this is the error i get when i run this function

ERROR
Value to add was out of range.
Parameter name: value

Open in new window




CODE
    Private Function ConvertFromUnixTimestamp(ByVal timestamp As Double) As DateTime
        Dim origin As New DateTime(1970, 1, 1, 0, 0, 0, _
         0)
        Return origin.AddSeconds(timestamp)
    End Function

Open in new window


NOTE: error happens on teh return
0
 
LVL 16

Accepted Solution

by:
Wasim Akram Shaik earned 500 total points
ID: 39993944
I believe this is something w.r.to variable type, the value which is being captured in the variable is not allowing that range of value..

check from that prospect.. i have found out a link for you.. see if this helps..in this link also its given that value is being returned in milli seconds, so you might change it to /1000 .. just have a look, you will get an idea..

http://stackoverflow.com/questions/15926261/convert-epoch-unix-to-datetime
0
 
LVL 1

Assisted Solution

by:Chris Jones
Chris Jones earned 0 total points
ID: 39993960
Awesome thank you it was the milliseconds that was throwing it off

i used that posts function as well

    Public Function ConvertUnixTimeStamp(ByVal unixTimeStamp As String) As System.Nullable(Of DateTime)
        Return New DateTime(1970, 1, 1, 0, 0, 0).AddMilliseconds(Convert.ToDouble(unixTimeStamp))
    End Function

Open in new window

0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 39993975
Welcome...!!! Glad that I could be of help :)
0
 
LVL 1

Author Closing Comment

by:Chris Jones
ID: 40105105
Thanks for the fast response
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!

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

737 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