当前位置:K88软件开发文章中心编程语言.NET.NET02 → 文章内容

VB.Net - 日期和时间

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-15 15:58:59

由 yiyohunter 创建,youj 最后一次修改 2016-12-12 你写的大部分软件都需要实现某种形式的日期功能,返回当前日期和时间。日期是日常生活的一部分,使用它能让工作变得轻松,不需要太多思考。 VB.Net还提供了强大的日期算术工具,使操作日期变得容易。 日期数据类型包含日期值,时间值或日期和时间值。 Date的默认值为0001年1月1日的0:00:00(午夜)。等效的.NET数据类型为System.DateTime。 DateTime 结构表示即时时间,通常表示为日期和时间的一天'Declaration<SerializableAttribute> _Public Structure DateTime _Implements IComparable, IFormattable, IConvertible, ISerializable, IComparable(Of DateTime), IEquatable(Of DateTime)您还可以从DateAndTime类获取当前日期和时间。 DateAndTime模块包含日期和时间操作中使用的过程和属性。 'Declaration<StandardModuleAttribute> _Public NotInheritable Class DateAndTime 注意: DateTime结构和DateAndTime模块都包含诸如Now和Today之类的属性,因此初学者经常会感到困惑。 DateAndTime类属于Microsoft.VisualBasic命名空间,DateTime结构属于System命名空间。因此,使用以后的将帮助你移植你的代码到另一个.Net语言,如C#。 但是,DateAndTime类/模块包含Visual Basic中所有可用的旧日期函数。 DateTime结构的属性和方法下表列出了一些DateTime结构的常用属性 : S.N属性描述1DateGets the date component of this instance.获取此实例的日期组件。2DayGets the day of the month represented by this instance.获取此实例所代表的月份中的某一天。3DayOfWeekGets the day of the week represented by this instance.获取此实例表示的星期几。4DayOfYearGets the day of the year represented by this instance.获取此实例表示的一年中的某一天。5HourGets the hour component of the date represented by this instance.获取此实例表示的日期的小时组件。6KindGets a value that indicates whether the time represented by this instance is based on local time, Coordinated Universal Time (UTC), or neither.G获取一个值,该值指示此实例表示的时间是基于本地时间,协调世界时间(UTC)还是两者都不是。7MillisecondGets the milliseconds component of the date represented by this instance.获取此实例表示的日期的毫秒组件。8MinuteGets the minute component of the date represented by this instance.获取此实例表示的日期的分钟分量。9MonthGets the month component of the date represented by this instance.获取此实例表示的日期的月份。10NowGets a DateTime object that is set to the current date and time on this computer, expressed as the local time.获取在此计算机上设置为当前日期和时间的DateTime对象,以本地时间表示。11SecondGets the seconds component of the date represented by this instance.获取此实例表示的日期的秒组件。12TicksGets the number of ticks that represent the date and time of this instance.获取表示此实例的日期和时间的刻度数。13TimeOfDayGets the time of day for this instance.获取此实例的时间。14TodayGets the current date.获取当前日期。15UtcNowGets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).获取设置为此计算机上当前日期和时间的DateTime对象,以协调世界时(UTC)表示。16YearGets the year component of the date represented by this instance.获取此实例表示的日期的年份组件。下表列出了DateTime结构的一些常用方法:SN方法名称和说明1Public Function Add (value As TimeSpan) As DateTime公共函数Add(值作为时间跨度)As DateTime 返回一个新的DateTime,将指定的TimeSpan的值添加到此实例的值。 2Public Function AddDays ( value As Double) As DateTime公共函数AddDays(值为双)As DateTime 返回一个新的DateTime,该值将指定的天数添加到此实例的值中。 3Public Function AddHours (value As Double) As DateTime公共函数AddHours(值为双)As DateTime 返回一个新的DateTime,该值将指定的小时数添加到此实例的值中。 4Public Function AddMinutes (value As Double) As DateTime公共函数AddMinutes(值为双)As DateTime 返回一个新的DateTime,将指定的分钟数添加到此实例的值。 5Public Function AddMonths (months As Integer) As DateTime公共函数AddMonths(月作为整数)As DateTime 返回一个新的DateTime,将指定的月数添加到此实例的值。 6Public Function AddSeconds (value As Double) As DateTime公共函数AddSeconds(值为双)As DateTime 返回一个新的DateTime,将指定的秒数添加到此实例的值。 7Public Function AddYears (value As Integer ) As DateTime公共函数AddYears(值为整数) As DateTime 返回一个新的DateTime,将指定的年数添加到此实例的值。 8Public Shared Function Compare (t1 As DateTime,t2 As DateTime) As Integer公共共享函数比较(T1作为日期时间,T2为DATETIME)As Integer 比较两个DateTime实例,并返回一个整数,指示第一个实例是早于,与第二个实例相同还是晚于第二个实例。 9Public Function CompareTo (value As DateTime) As Integer公共函数CompareTo(值为DATETIME)As Integer 将此实例的值与指定的DateTime值进行比较,并返回一个整数,指示此实例是早于,等于还是晚于指定的DateTime值。 10Public Function Equals (value As DateTime) As Boolean公共函数等于(值为DATETIME)As Boolean 返回一个值,表示此实例的值是否等于指定的DateTime实例的值。 11Public Shared Function Equals (t1 As DateTime, t2 As DateTime) As Boolean公共共享函数等于(T1作为日期时间,T2为DATETIME) As Boolean 返回一个值,指示两个DateTime实例是否具有相同的日期和时间值。 12Public Overrides Function ToString As String公共覆盖函数ToString  As String将当前DateTime对象

[1] [2] [3] [4]  下一页


VB.Net - 日期和时间