当前位置: 首页 > 图文教程 > 开发语言 > VB > 在ASP.NET中处理datetime的一些通用函数(VB)

VB
串口通讯及其在VB平台下的实现
VB中用API实现文件拖放
VB表格控件总览与例程分析
在VB中用DAO实现数据库编程
VB6将XML数据传入TreeView控件
VB和VB.NET中的XML操作
用VB.NET实现你的游戏梦想
用FileStreams将DTD插入XML中
Visual Basic.NET编程的设计思考
用VB设计控制上网时间程序
VB.NET实现Windows进程管理器
VB.NET启动并监测外部程序
VB6.0数据库访问技术与例程解析
VB.NET开发扫描客户端服务工具
VB制作一个通信卡片ActiveX控件
用VB6.0设计一个打字练习软件
消息队列在VB.NET数据库开发中的应用
用VB6.0快速实现图象加柔效果
VB6.0设计真正实用的TreeView控件
优化之路:精简VB中的分段应用程序(上)

在ASP.NET中处理datetime的一些通用函数(VB)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-29   浏览: 90 ::
收藏到网摘: n/a

Uses the Timespan method to subtract a certain number of days
Function Date1()
Dim NewTime as DateTime
NewTime = DateTime.Now.Subtract( New TimeSpan(7, 0, 0, 0) )
NewTime = NewTime.Format("MM/dd/yyyy", DateTimeFormatInfo)
response.write(NewTime)
End Function

Uses the AddDays method to subtract X number of days
Public Function Date2()
Dim NewTime as DateTime
NewTime = DateTime.Now.AddDays(-7)
Dim s as string = NewTime
return s
End Function

Thanks to Paul Czywczynski for this idea
This probably (In My opinion) Offers the most flexibility found so far
Change where the MM/dd/yyyy to whatever
response.write(System.String.Format("{0:d}",NewTime))
would return just the name of the Day
Function Date3()
Dim NewTime as DateTime = now.addDays(-7)
response.write(System.String.Format("{0:MM/dd/yyyy}",NewTime))
End Function


Function Date4()
Dim NewTime as DateTime
NewTime = now.addDays(-7)
return NewTime.ToString()
End Function

Uses the toLongTimeString method
Public Function Date5()
Dim NewTime as DateTime
NewTime = Now()
return newtime.toLongTimeString()
End Function

Uses the toShortTimeString method
Public Function Date6()
Dim NewTime as DateTime
NewTime = Now()
return newtime.toShortTimeString()
End Function

Uses the toLongDateString method
Public Function Date7()
Dim NewTime as DateTime
NewTime = Now()
return newtime.toLongDateString()
End Function

Uses the toShortDateString method
Public Function Date8()
Dim NewTime as DateTime
NewTime = Now()
return newtime.toShortDatestring()
End Function

Uses FormatDateTime function General format
Function Date9()
Dim NewTime as DateTime
NewTime = DateTime.Now.Subtract( New TimeSpan(7, 0, 0, 0) )
return formatdatetime(NewTime, 0)
End Function

Uses FormatDateTime function LongDate format
Function Date10()
Dim NewTime as DateTime
NewTime = DateTime.Now.Subtract( New TimeSpan(7, 0, 0, 0) )
return formatdatetime(NewTime, 1)
End Function

Uses FormatDateTime function ShortDate format
Function Date11()
Dim NewTime as DateTime
NewTime = DateTime.Now.Subtract( New TimeSpan(7, 0, 0, 0) )
return formatdatetime(NewTime, 2)
End Function

Uses FormatDateTime function LongTime format
Function Date12()
Dim NewTime as DateTime
NewTime = DateTime.Now.Subtract( New TimeSpan(7, 0, 0, 0) )
return formatdatetime(NewTime, 3)
End Function

Uses FormatDateTime function ShortTime format
Function Date13()
Dim NewTime as DateTime
NewTime = DateTime.Now.Subtract( New TimeSpan(7, 0, 0, 0) )
return formatdatetime(NewTime, 4)
End Function

Bring Back just the name of the Day
Function Date14()
Dim NewTime as DateTime = now.addDays(-7)
dim s as string
s = (System.String.Format("{0:dddd}",NewTime))
Return s
End Function

Returns the Integer of what day of week
Function Date15()
Dim MyDate as DateTime
Dim MyWeekDay as Integer
MyDate = Now.AddDays(-5)
MyWeekDay = Weekday(MyDate)
return MyWeekDay
End Function

Returns the Month Integer
Function Date16()
Dim MyDate as DateTime
Dim MyMonth as Integer
MyDate = Now.AddDays(-5)
MyMonth = Month(MyDate)
return MyMonth
End Function

Returns just a formatted string
This method provides just formatting but
Very flexible with not a lot of code
Function Date17()
Dim MyDate as String
MyDate = Format(Now(), "yyyy")
return MyDate
End Function