將日期轉成Unix Timestamp。
Private Const Unix1970 As Long = 25569 'CDbl(DateSerial(1970, 1, 1)) Public Function Date2Unix(ByVal vDate As Date) As Long Date2Unix = DateDiff("s", Unix1970, vDate) End Function
將 Unix Timestamp 轉成日期。
Private Const Unix1970 As Long = 25569 'CDbl(DateSerial(1970, 1, 1)) Public Function Unix2Date(vUnixDate As Long) As Date Unix2Date = DateAdd("s", vUnixDate, Unix1970) End Function
或
Private Const Unix1970 As Long = 25569 'CDbl(DateSerial(1970, 1, 1)) Public Function Unix2Date(vUnixDate As Long) As String Unix2Date = Format(DateAdd("s", vUnixDate, Unix1970), "yyyy/mm/dd") End Function
參考資料: