1.时间 转 时间戳
Dim localDateTime As DateTime = DateTime.Now ' 本地时间
' 将本地时间转换为 Unix 时间戳(秒)
Dim unixTimestamp As Long = New DateTimeOffset(localDateTime).ToUnixTimeSeconds()
' 将本地时间转换为毫秒级 Unix 时间戳
Dim unixTimestampMilliseconds As Long = New DateTimeOffset(localDateTime).ToUnixTimeMilliseconds()
2.时间戳 转 时间
' 将秒级 Unix 时间戳转换为本地时间
Dim unixTimestamp As Long = 1704271702
Dim dateTime As DateTime = DateTimeOffset.FromUnixTimeSeconds(unixTimestamp).LocalDateTime
' 将毫秒级 Unix 时间戳转换为本地时间
Dim unixTimestampMilliseconds As Long = 1641650378000 ' 例如:毫秒级 Unix 时间戳
Dim localDateTime As DateTime = DateTimeOffset.FromUnixTimeMilliseconds(unixTimestampMilliseconds).LocalDateTime