Solved

function to convert UNIX time to human time in .net

Posted on 2014-04-10
8
461 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
 
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
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.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now