5.4. Formatting date and time values

In Chapter 3, we saw how to use the various formatting specifiers to produce the string representation of values in different formats. Here we will look at how to use the date and time format strings to represent the DateTime data type in various formats. Without providing much reference information about the format specifiers available, let's look at an example that shows how to use each format specifier available – its output shows you exactly what to expect in each case (see also Figure 5.7):

 '---------------------------------------- ' .NET DateTime formatting example '---------------------------------------- Imports System Module Module1 Sub Main() Dim Formats() As String = _ {"Short date : {0:d}", _ ...

Get A Programmer's Guide to .NET 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.