function to convert UNIX time to human time in .net

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"))
LVL 1
Chris JonesLead Application Web DeveloperAsked:
Who is Participating?
 
Wasim Akram ShaikConnect With a Mentor Commented:
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
 
Chris JonesLead Application Web DeveloperAuthor Commented:
Yes I have reviewed and tried both links and I get the similar error.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Wasim Akram ShaikCommented:
what kind of error have you got?

Please post error message which will help our experts review and suggest ..!!
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
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
 
Chris JonesConnect With a Mentor Lead Application Web DeveloperAuthor Commented:
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
 
Wasim Akram ShaikCommented:
Welcome...!!! Glad that I could be of help :)
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
Thanks for the fast response
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.