Excel VBA:将日期字符串转换为 Unix 时间戳 [英] Excel VBA: Convert a date string to a Unix timestamp

查看:25
本文介绍了Excel VBA:将日期字符串转换为 Unix 时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Excel VBA:如何转换日期字符串
2012-08-20"到时间戳:1345438800
我需要将 1345438800 作为长数据类型值存储在单元格中.

Excel VBA: How to convert date string
"2012-08-20" to timestamp: 1345438800
I need to store 1345438800 in cell as long data type value.

推荐答案

日期到时间戳:

Public Function toUnix(dt) As Long
    toUnix = DateDiff("s", "1/1/1970", dt)
End Function

迄今为止的时间戳:

Public Function fromUnix(ts) As Date
    fromUnix = DateAdd("s", ts, "1/1/1970")
End Function

这篇关于Excel VBA:将日期字符串转换为 Unix 时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆