Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 获取一个月最后一天的最后一个en_Vb.net - Fatal编程技术网

Vb.net 获取一个月最后一天的最后一个en

Vb.net 获取一个月最后一天的最后一个en,vb.net,Vb.net,我有一个类似于2010年12月27日(日-月-年)的日期。我需要返回以下值 31-12-2010(当月最后一天) 2010年12月30日(该月的最后一天)若要指定该月的最后一天,请使用以下命令: Dim original As DateTime = DateTime.Now ' The date you want to get the last day of the month for Dim lastOfMonth As DateTime = original.Date.AddDays(-(o

我有一个类似于2010年12月27日(日-月-年)的日期。我需要返回以下值

31-12-2010(当月最后一天)


2010年12月30日(该月的最后一天)

若要指定该月的最后一天,请使用以下命令:

Dim original As DateTime = DateTime.Now ' The date you want to get the last day of the month for
Dim lastOfMonth As DateTime = original.Date.AddDays(-(original.Day - 1)).AddMonths(1).AddDays(-1)

有点啰嗦,但它保证你不会以某种方式结束下个月的第一天或本月的第二天到最后一天。

获取本月的开始日期和最后一天:

Dim thisMonth As New DateTime(DateTime.Today.Year, DateTime.Today.Month, 1)

'beginning day of the month
thisMonth.ToString("yyyy-MM-01")

'last day of the month
thisMonth.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd")

如果你接受了答案,人们会更愿意提供帮助。从半命令式的“我需要价值观”到类似“如何做到这一点?”——或者甚至是一些代码,向你展示当前的方法以及你的问题是什么?我认为这不是一个好方法(即使它可能有效),因为您总是希望避免转换,尤其是转换为字符串。它的性能很差。这还考虑到闰年,它将显示每个月的最后一天+1是的。它所做的就是得到当前月份的第一天,加上一个月(总是给我们下个月的第一天),然后减去一天。