13.3. Date and Time Formatting

This section explores the date and time formatting capabilities of C#. In Java, the java.text.DateFormat class provides methods such as getTimeInstance(), getDateTimeInstance(), and getDateInstance(). These methods take optional locale information to create a DateFormat instance. You can gain some level of control over the formatting by specifying whether the format to be used is LONG, SHORT, or MEDIUM. However, the formatted string always follows a standard pattern. To change that pattern and to gain finer control of the formatted date, you use java.text.SimpleDateFormat, whose constructor takes a pattern string. The pattern string consists of date- and time-related symbols. For example, consider the following ...

Get .NET for Java Developers: Migrating to C# 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.