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

原创 2005年04月27日 15:04:00
'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

Asp.net DateTime格式化

DateTime dt = DateTime.Now; // Label1.Text = dt.ToString();//2005-11-5 13:21:25 // Label2.Text = d...

[ASP.NET] SQL SERVER 最全的datetime格式转化

将sqlserver中table表的[datetime]字段值‘2016-12-08 16:41:35.033’ 改为‘2016-12-08 00:00:00‘去除了时分秒.[datetime]字段要...

解决Asp.net Mvc返回JsonResult中DateTime类型数据格式的问题

问题背景:            在使用asp.net mvc 结合jquery esayui做一个系统,但是在使用使用this.json方法直接返回一个json对象,在列表中显示时发现datetim...

VB+asp.net上传文件

MultiUpload.aspx<%@ Page Language="vb" AutoEventWireup="false" Codebehind="MultiUpload.aspx.vb" ...

asp.net vb新闻页动态生成静态页面的实例代码

首先 建立一个页面1.html  模板页 生成静态页有很多好处,可以缓解服务器压力、方便搜索网站搜索等等,下面介绍一下生成静态页的实例代码,有需要的朋友可以参考一下 最近突然想把项目中...

Asp.net利用事件委托,实现用户控件中的行为触发所在页面的处理函数

Asp.net利用事件委托,实现用户控件中的行为触发所在页面的处理函数 在日常的工作中,我们时常会遇到这样的需求:点击一用户控件中的服务器按 钮,变更页面上该用户控件以外某处的数据显示。这样就...

ASP.Net 获取服务器的当前日期时间的综合处理函数!

//获取日期+时间 DateTime.Now.ToString(); // 2008-9-4 20:02:10 DateTime.Now.ToLocalTime().ToSt...
  • dxnn520
  • dxnn520
  • 2012年11月24日 06:51
  • 6315

C# asp.net中常见的字符串处理函数及数字格式化

//1.字符串比较 //字符串.ComparTo(目标字符串) "a".ComparTo("b"); //2.查找子串 //字符串.In...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:在ASP.NET中处理datetime的一些通用函数(VB)
举报原因:
原因补充:

(最多只允许输入30个字)