vb.net 获取日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1672832/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:30:28  来源:igfitidea点击:

Getting the day of a date

vb.netdate

提问by Matt

I have a series of dates formatted as:

我有一系列日期格式为:

26/03/1992
12/06/2010
13/01/1995

26/03/1992
12/06/2010
13/01/1995

etc... it's in DD/MM/YYYY. I need to find the day like "Tuesday", "Monday" etc out of them.

等等......它在DD/MM/YYYY中。我需要从中找出像“星期二”、“星期一”等这样的日子。

I know I need to parse the date or something but I'm unsure how to go about this.

我知道我需要解析日期或其他内容,但我不确定如何处理。

回答by Fermin

You can cast it as a DateTime and use the DayOfWeek property which returns a DayOfWeek enumerator.

您可以将其转换为 DateTime 并使用返回 DayOfWeek 枚举器的 DayOfWeek 属性。

Not sure in VB.NET but in C# it's like

在 VB.NET 中不确定,但在 C# 中就像

DateTime.Now.DayOfWeek or DateTime.Parse(theDateString).DayOfWeek

回答by PhilPursglove

You want to look at the format strings for the ToStringmethod. MyDate.ToString("dddd")will get you what you want.

您想查看ToString方法的格式字符串。MyDate.ToString("dddd")会给你你想要的。

回答by n3xus

DateTime.Parse("2010/12/31").dayofweek

回答by Beshara

The best thing it works for me in vb 2010 is

它在 vb 2010 中对我最有用的是

I add timer and enabled it then i put it like that

我添加计时器并启用它然后我把它像这样

Label6.Text = Format(Now, "dddd/dd")

"dd"gives me the day Num. "dddd"gives me the name of the day

"dd"给我天数。 "dddd"给我一天的名字

回答by Ram

'Declaration
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class ArgumentOutOfRangeException
    Inherits ArgumentException
    Implements ISerializable
'Usage
Dim instance As ArgumentOutOfRangeException

回答by almog.ori

Try

尝试

dateValue.DayOfWeek.ToString()

回答by xpda

Convert the date into a date datatype, then use the format function. This displays monday:

将日期转换为日期数据类型,然后使用 format 函数。这显示星期一:

Dim d As Date
d = "11/23/2009"
MsgBox(Format(d, "dddd"))

You could also get a numeric day of the week using d.DayOfWeek.

您还可以使用 d.DayOfWeek 获得一周中的数字日期。

回答by Heinzi

Have a look at the documentationof the DateTime members Parse, TryParse, DayOfWeek and ToString.

查看DateTime 成员 Parse、TryParse、DayOfWeek 和 ToString的文档

回答by Jerwin P.

In VB try this:

在VB中试试这个:

DateTimePicker1.Value.DayOfWeek.ToString

It works

有用

回答by Ahmed Hassan

MsgBox(Now.Date.DayOfWeek.ToString)