.NET Applications
XML Web Services
SQL Server Database
Web Traffic Statistics
Much More... |
| |
|
| Windows
2003 Server
2.4 GHz Pentium 4
1024 MB RAM
80 GB Hard Drive
1000 GB/month
Fully Managed
Free Setup!
$268.00/month |
| |
|
10 or more Domains
Windows Services
Custom Plans |
| |
|
|
|
More ASP.NET
Tutorials
Working with Dates and Time in ASP.NET using Visual Basic.NET is not complicated.
First we set the initial DateTime variable as follows:
Dim dtNow As DateTime = DateTime.Now
Now we can use this variable to manipulate today's date to give us the exact format that we
need.
We have created a Literal control for each time variable below.
We then assign the each variable below to the .Text property of the Literal control. |
| 9/5/2008 9:44:07 PM |
| litNow.Text = dtNow.ToString |
| 9/5/2008 |
| litDate.Text = dtNow.Date |
| 9/5/2008 |
| litToday.Text = dtNow.Today |
| 9/5/2008 |
| litToShortDateString.Text = dtNow.ToShortDateString |
| 9:44 PM |
| litToShortTimeString.Text = dtNow.ToShortTimeString |
| Friday, September 05, 2008 |
| litToLongDateString.Text = dtNow.ToLongDateString |
| 9:44:07 PM |
| litToLongTimeString.Text = dtNow.ToLongTimeString |
| 9/6/2008 2:44:07 AM |
| litToUniversalTime.Text = dtNow.ToUniversalTime |
| 249 |
| litDayOfYear.Text = dtNow.DayOfYear |
| 5 |
| litDayOfWeek.Text = dtNow.DayOfWeek |
| 9 |
| litDay.Text = dtNow.Month |
| 5 |
| litDay.Text = dtNow.Day |
| 2008 |
| litDay.Text = dtNow.Year |
| 9/6/2008 9:44:07 PM |
| litAddDays.Text = dtNow.AddDays(1) |
| 9/5/2008 10:44:07 PM |
| litAddHours.Text = dtNow.AddHours(1) |
| 9/5/2008 9:44:17 PM |
| litAddMilliseconds.Text = dtNow.AddMilliseconds(10000) |
| 9/5/2008 9:45:07 PM |
| litAddMinutes.Text = dtNow.AddMinutes(1) |
| 10/5/2008 9:44:07 PM |
| litAddMonths.Text = dtNow.AddMonths(1) |
| 9/5/2008 9:44:08 PM |
| litAddSeconds.Text = dtNow.AddSeconds(1) |
| 9/7/2008 1:30:47 AM |
| litAddTicks.Text = dtNow.AddTicks(1000000000000) |
| 9/5/2009 9:44:07 PM |
| litAddYears.Text = dtNow.AddYears(1) |
|
9/4/2008 9:44:07 PM |
| litAddNegDays.Text = dtNow.AddDays(-1) |
|
9/5/2007 9:44:07 PM |
| litAddNegYears.Text = dtNow.AddYears(-1) |
Also See:
Anthony Moore provides a FAQ
about date and time related classes, including System.DateTime, System.TimeSpan and
System.TimeZone |
Do you have an ASP.NET Tutorial you would like to see here? Contact
Us!
|
|