Login or Sign Up to become a member!
LessThanDot Site Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

VB.Net: Add time to a date (hours, minutes, seconds)

From Wiki

Jump to: navigation, search

In .Net you can easily make a date and add hours, minutes and seconds to it.

  1. Module Module1
  2.  
  3.     Sub Main()
  4.         Dim _Date As New Date(2008, 6, 12, 12, 12, 12)
  5.         Console.WriteLine("begin")
  6.         Console.WriteLine(_Date.ToString("dd/MM/yyyy HH/mm/ss"))
  7.         _Date = _Date.AddHours(10)
  8.         Console.WriteLine("added 10 hours")
  9.         Console.WriteLine(_Date.ToString("dd/MM/yyyy HH/mm/ss"))
  10.         _Date = _Date.AddMinutes(10)
  11.         Console.WriteLine("added 10 minutes")
  12.         Console.WriteLine(_Date.ToString("dd/MM/yyyy HH/mm/ss"))
  13.         _Date = _Date.AddSeconds(10)
  14.         Console.WriteLine("added 10 seconds")
  15.         Console.WriteLine(_Date.ToString("dd/MM/yyyy HH/mm/ss"))
  16.         _Date = _Date.Add(New TimeSpan(10, 10, 0, 10, 0))
  17.         Console.WriteLine("added 10 days, 10 hours and 10 seconds with timespan")
  18.         Console.WriteLine(_Date.ToString("dd/MM/yyyy HH/mm/ss"))
  19.         Console.ReadLine()
  20.     End Sub
  21.  
  22. End Module

This will give as result.

Resulttimeadding.jpg

540 Rating: 3.1/5 (16 votes cast)