如何在VB中以mm / dd / yyyy格式打印日期 [英] How to print date in the format of mm/dd/yyyy in VB
问题描述
我需要以mm / dd / yyyy格式打印日期。
如果日期为4/24/2009,则应将日期打印为04/24/2009。
也需要填充为零。.
我使用date函数来获取当前日期...但是该日期的格式为m / dd / yyyy ...
I need to print the date in the format of mm/dd/yyyy. if the date is 4/24/2009 it should print the date as 04/24/2009. that is zero padding is also needed.. I used date function to get the current date...but the date is getting in the format of m/dd/yyyy...
推荐答案
在立即窗口中进行了测试,并正在为我工作(作为注释输出)
Tested in the immediate window and is working for me (output as a comment)
Format(Now, "MM/dd/yyyy") '04/29/2009
Format(Date, "MM/dd/yyyy") '04/29/2009
Format(CStr(Now), "MM/dd/yyyy") '04/29/2009
Format(Date$, "MM/dd/yyyy") '04/29/2009
Format(CDate(Date), "MM/dd/yyyy")'04/29/2009
因此,无论是字符串还是日期时间都无关紧要。
So whether it is string or datetime should not matter.
编辑:看到您对Fredrik的评论。将其保存到db表中时,它的外观无关紧要(列日期格式是db的属性,而不是程序(或vb)的责任)。从数据库中检索值时,只需格式化该值即可。
Saw your comment to Fredrik. It doesn't matter how it looks like when you save it to the db table (column date format would be a property of the db and not your program's (or vb's) responsibility). Just format the value as and when you retrieve it from the db.
这篇关于如何在VB中以mm / dd / yyyy格式打印日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!