首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

关于日期转换计算的有关问题

2012-02-25 
关于日期转换计算的问题我有一个日期型变量,该值作为参数传入,我还定义了个日期型变量,我想再接入该变量后

关于日期转换计算的问题
我有一个日期型变量,该值作为参数传入,我还定义了个日期型变量,我想再接入该变量后,将该日期设为两个时间,1个是起始时间,另1个是结束时间

如“2009/01/20”(该值为日期型) 传入后, 

Dim dtstart as date = '2009-01-01'
Dim dtfinish as date = '2009-01-31' (如1月最后1天为31;2月为29或28)

请问应如何实现呢,谢谢!


[解决办法]

VB.NET code
    Private Function GetLastDate(ByVal istrYMD As String) As Date        Dim objDate As DateTime = DateTime.Parse(istrYMD)        Dim intYear As Integer = objDate.Year        Dim intMonth As Integer = objDate.Month        Dim intDay As Integer = DateTime.DaysInMonth(intYear, intMonth)        Return New DateTime(intYear, intMonth, intDay)    End Function    Private Function GetFirstDate(ByVal istrYMD As String) As Date        Dim objDate As DateTime = DateTime.Parse(istrYMD)        Dim intYear As Integer = objDate.Year        Dim intMonth As Integer = objDate.Month        Dim intDay As Integer = 1        Return New DateTime(intYear, intMonth, intDay)    End Function
[解决办法]
日期类功能很全了哦,


Module Module1

Sub Main()
Dim start As DateTime
Dim finish As DateTime
GetDate(DateTime.Now, start, finish)
Console.WriteLine(start.ToString("yyyy-MM-dd"))
Console.WriteLine(finish.ToString("yyyy-MM-dd"))
End Sub

Sub GetDate(ByVal dt As DateTime, ByRef startDate As DateTime, ByRef finishDate As DateTime)
startDate = New DateTime(dt.Year, dt.Month, 1)
finishDate = New DateTime(dt.Year, dt.Month, DateTime.DaysInMonth(dt.Year, dt.Month))
End Sub

End Module

引用上面的。

热点排行