VB.NET 日期时间操作指南

提供 VB.NET 中日期和时间操作的实用指南,涵盖常见场景和代码示例。

获取当前日期和时间

Dim now As DateTime = DateTime.Now 
Console.WriteLine("当前日期和时间:" & now)

格式化日期和时间

Dim formattedDate As String = now.ToString("yyyy-MM-dd")
Console.WriteLine("格式化日期:" & formattedDate)

日期时间计算

Dim tomorrow As DateTime = now.AddDays(1)
Console.WriteLine("明天:" & tomorrow)

比较日期时间

Dim date1 As DateTime = #2023/10/26#
Dim date2 As DateTime = #2023/10/27#

If date1 < date2>

更多日期时间操作方法请参考 MSDN 文档。

rar 文件大小:86.45KB