0

I have used the code:

Dim val = ( _
        New DateTime( _
            DateTimePicker1.Value.Year, _
            DateTimePicker1.Value.Month, _
            DateTimePicker1.Value.Day, _
            CInt(TextBox1.Text), _
            CInt(TextBox2.Text), _
            0 _
        ) _
        - _
        New DateTime(1970, 1, 1, 0, 0, 0) _
    ).TotalMilliseconds
val = val + (CInt(TextBox2.Text) * 1000)

to get the milliseconds from 01/01/1970 using the selected input date and time. Does anyone know how to convert this value back into something that I can use to display the date in a DateTimePicker along with the hours and minutes that I can use some-place else?

4

2 回答 2

5

使用DateTime对象的AddMilliseconds()方法,如下所示:

' Calculation of milleseconds
Dim val = (New DateTime(DateTimePicker1.Value.Year, DateTimePicker1.Value.Month, DateTimePicker1.Value.Day, CInt(TextBox1.Text), CInt(TextBox2.Text), 0) - New DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds

' Start with new date object as January 1st, 1970 and then add milliseconds calculated above
Dim dateJan1st1970 As New DateTime(1970, 1, 1, 0, 0, 0)
Dim dateNew As DateTime = dateJan1st1970.AddMilliseconds(val)
于 2013-11-07T19:37:14.917 回答
3

哇,这太复杂了:

Dim epoch As New DateTime(1970, 1, 1, 0, 0, 0)

Dim val = (DateTimePicker1.Value.AddSeconds(CInt(TextBox2.Text)) - epoch).TotalMilliseconds
于 2013-11-07T19:40:58.647 回答