Solved

function to convert UNIX time to human time in .net

Posted on 2014-04-10
8
488 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 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
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 
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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

690 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