为了将秒数转换为DateTime,在VB .NET中,我使用以下代码:
- Dim startDate As New DateTime(1970,1,1)
- Dim targetDate As DateTime
- Dim noOfSeconds As Integer = DataInSeconds
- targetDate = startDate.AddSeconds(noOfSeconds)
其中DataInSeconds是一个包含秒数的整数(从1970年1月1日开始)
这很好用.但我不知道如何进行逆转换. (从DateTime到秒数).有人可以帮帮我吗?
当你从彼此中减去DateTime实例时,你得到一个
TimeSpan
– 你可以使用它来获得秒数:
- Dim startDate As New DateTime(1970,1)
- Dim noOfSeconds As Integer
- noOfSeconds = (currentDate - startDate).TotalSeconds