Solved

function to convert UNIX time to human time in .net

Posted on 2014-04-10
8
466 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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:…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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 find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

803 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