vb.net 在 Visual Basic 2008 中获取当前日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9177199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting the current date in visual Basic 2008
提问by Tamseyc
I dont know how to get the current date in visual basic 2008. Here is a sample code
我不知道如何在 Visual Basic 2008 中获取当前日期。这是一个示例代码
regDate = Format(Date.Now(), "ddMMMyyyy")
The output is like 7/02/1900
输出就像 7/02/1900
Need help
需要帮忙
回答by Anirudh
User can use this
用户可以使用这个
Dim todaysdate As String = String.Format("{0:dd/MM/yyyy}", DateTime.Now)
this will format the date as required whereas user can change the string type dd/MM/yyyy or MM/dd/yyyy or yyyy/MM/dd or even can have this format to get the time from date
这将根据需要格式化日期,而用户可以更改字符串类型 dd/MM/yyyy 或 MM/dd/yyyy 或 yyyy/MM/dd 甚至可以使用此格式从日期获取时间
yyyy/MM/dd HH:mm:ss
回答by Boeckm
Try this:
尝试这个:
Dim regDate as Date = Date.Now()
Dim strDate as String = regDate.ToString("ddMMMyyyy")
strDate will look like so: 07Feb2012
strDate 看起来像这样: 07Feb2012
回答by Mark Hurd
You may just want:
您可能只想要:
Dim regDate As Date = Date.Today()
回答by BlackBada
If you need exact '/' delimiters, for example: 09/20/2013 rather than 09.20.2013, use escape sequence '/':
如果您需要精确的“/”分隔符,例如:09/20/2013 而不是 09.20.2013,请使用转义序列“/”:
Dim regDate As Date = Date.Now()
Dim strDate As String = regDate.ToString("MM\/dd\/yyyy")
回答by user3882642
Dim regDate As Date = Date.Now.date
This should fix your problem, though it's 2 years old!
这应该可以解决您的问题,尽管它已经 2 岁了!