Skip to Main Content
C# in a Nutshell, Second Edition
book

C# in a Nutshell, Second Edition

by Peter Drayton, Ben Albahari, Ted Neward
August 2003
Intermediate to advanced content levelIntermediate to advanced
928 pages
32h 1m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell, Second Edition

Name

DateTime

Synopsis

This simple value type represents a moment in time from 12:00:00 A.M., 1/1/0001 C.E. (Common Era), to 11:59:59 P.M., 12/31/9999 C.E., which is measured to the nearest tick, or 100-nanosecond interval. You can use this type in greater-than/less-than comparisons, sorting, and in calculations using other DateTime or TimeSpan instances. You can also use convenient Add. . . methods, such as AddSeconds( ), with a positive or negative value.

To extract part of a date, use properties such as Day and Minute. All properties except Ticks represent a single component of a compound date, not the whole date. You can convert a string into a DateTime using the static Parse( ) or ParseExact( ) methods, which require that the date match the pattern specified by a supplied format string.

The DateTime class also provides valuable static functions that can determine the number of days in a month (DaysInMonth( )), evaluate whether a year is a leap year (IsLeapYear( )), and retrieve the date stamp from a file (FromFileTime( )). You can also get the current date from the static property Today (or UtcNow for the coordinated universal time).

public struct DateTime : IComparable, IFormattable, IConvertible {
// Public Constructors
   public DateTime(int year, int month, int day);
   public DateTime(int year, int month, int day, System.Globalization.Calendar calendar);
   public DateTime(int year, int month, int day, int hour, int minute, int second);
   public DateTime(int year, int month, int day ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# in a Nutshell

C# in a Nutshell

Ben Albahari, Ted Neward, Peter Drayton
C# 7.0 in a Nutshell

C# 7.0 in a Nutshell

Joseph Albahari, Ben Albahari
C# Cookbook, 2nd Edition

C# Cookbook, 2nd Edition

Jay Hilyard, Stephen Teilhet
C# Cookbook

C# Cookbook

Joe Mayo

Publisher Resources

ISBN: 0596005261Catalog PageErrata