Determine Days of the Week, Leap Years, and More

Problem

You want to determine date information, such as what day of the week a given date falls on, whether a year is a leap year, and how many days are in a month.

Solution

Use a Calendar-derived class from the System.Globalization namespace, such as GregorianCalendar, or use the properties of a DateTime object.

Discussion

The System.Globalization namespace includes classes that contain culture-related calendar information. These classes derive from the base class Calendar and include GregorianCalendar (the Western standard), HebrewCalendar, JulianCalendar, JapaneseCalendar, and so on.

The Calendar classes define a number of basic methods, including:

  • GetDaysInMonth returns the number of days in a given ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.