Convert Time into Integer using C# and VB.Net in ASP.Net

Danny
 
on Dec 01, 2021 09:58 PM
Sample_461425.zip
625 Views

Need to convert Time into integer

private long ConvertToTimestamp(TimeSpan value)
{
    long epoch = (value.Ticks + 621355968000000000) / 10000000;
    return epoch;
}

The above function converting the Time into int but givining the wrong input

Download FREE API for Word, Excel and PDF in ASP.Net: Download
arjunv
 
on Dec 02, 2021 01:37 AM

 Hi Danny,

 Please refer below Code.

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        TimeSpan timeSpan = new TimeSpan(20, 23, 20);
        Response.Write(this.ConvertTimeToInt(timeSpan));
    }
}

public long ConvertTimeToInt(TimeSpan input)
{
    return input.Ticks;
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        Dim timeSpan As TimeSpan = New TimeSpan(20, 23, 20)
        Response.Write(Me.ConvertTimeToInt(timeSpan))
    End If
End Sub

Public Function ConvertTimeToInt(ByVal input As TimeSpan) As Long
    Return input.Ticks
End Function

Screenshot