打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
VBA代码实例之Format一招鲜搞定所有关于日期的问题

关于日期的问题,这篇就够了。

Format一招鲜,搞定关于日期的问题

代码如下:

Sub 文本转日期()

r = Sheet1.Range('a65536').End(3).Row

With Sheet1

For i = 3 To r

.Cells(i, 2) = Format(.Cells(i, 1), 'yyyy年mm月dd日') '年月日

.Cells(i, 3) = Format(Now, 'yyyy年mm月dd日 h:mm:ss') '日期精确到时分秒

.Cells(i, 4) = Date - 1 '昨天的日期

.Cells(i, 5) = Date '今天的日期

.Cells(i, 6) = Date + 1 '明天的日期

.Cells(i, 7) = Format((.Cells(i, 3)), 'yyyy') & '年' '从日期中提取年

.Cells(i, 8) = Format((.Cells(i, 3)), 'dd') & '月' '从日期中提取月

.Cells(i, 9) = Format(.Cells(i, 3), 'd') & '日' '从日期中提取日

.Cells(i, 10) = Format(.Cells(i, 3), 'H') & '点' '从日期中提取时

.Cells(i, 11) = Format(.Cells(i, 3), 'mm') & '分' '从日期中提取分

.Cells(i, 12) = Format(.Cells(i, 3), 'ss') & '秒' '从日期中提取秒

.Cells(i, 13) = Format(.Cells(i, 3), 'aaaa') '中文星期

.Cells(i, 14) = Format(.Cells(i, 3), 'dddd') '英文星期

.Cells(i, 15) = Format(.Cells(i, 3), 'ddd') '英文星期简写

Next i

End With

'--------在做处理数据的时候,可以用一下这段代码!

startTime = Time

MsgBox ('运行此流程共耗时:' & DateDiff('s', startTime, Time) & '秒')

End Sub

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
日期格式yyyy:MM:dd 改为yyyy-MM-dd?
java日期和字符串转换
[转载]Excel VBA中关于Format函数的用法集锦
delphi中日期格式的设定
字符串转为日期格式 java
struts2中的日期格式化输出
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服