aAbAEDAsABBfBrArXW| 76496}FW 747}FZ 774VCCB 76666V~C~ 798}5RW-~~~~P64V~~~~ 768V~~~WC-~~~~~~Z 747V 747VP4VBWCC 747VC 7884V

DateTime format.` The sundial casts a shadow that tells time. The time is formatted upon the stone surface. Format codes represent time, and dates, in different ways.`With format codes,` we encounter strange things like "M" and "dddd." Here the case of the letters (and the number of them) are important.`First example.` Let us examine a simple C# program. Here we combine many format codes. We use a formatting string with DateTime and ToString. `The letters in the format string specify the output. The final part (in the example) describes the format patterns.`Example, modified format.` Here we modify the format string in the above example to get different output. We change some of the fields—the resulting string value is shorter. `We need to specify a format string when using DateTime.ParseExact and DateTime.ParseExact.`Single-char format.` We use a char with ToString or DateTime.ParseExact to specify a preset format. These are standard formats. They are useful in many programs. `DateTime.Parse `datetime-parse`Date strings.` Here we see the ToLongDateString, ToLongTimeString, ToShortDateString, and ToShortTimeString methods on DateTime. These methods use formats. `These methods are equivalent to the lowercase and uppercase D and T methods shown in the example above.`Note 2: `The default ToString on DateTime is equivalent to the "G" formatting string. ToString("G") and ToString() do the same thing.`string.Format `format`Seconds format.` Seconds are formatted with f, F and s. The uppercase F changes how trailing zeros are displayed. And the lowercase s changes how leading zeros are displayed. `Lowercase f: `Use the lowercase f to indicate the seconds to one digit length. Use "ff" to indicate the seconds to two digits.`The uppercase F patterns do the same but work differently on trailing zeros.`Lowercase s: `The lowercase s displays seconds. With ss we always want two digits, such as 00-59.`Minutes format.` We use the lowercase m or mm for minutes. Two lowercase ms has a leading zero if the number is only one digit long. This is the only difference. `The two ms means that there are always two digits displayed, with a leading zero if necessary.`Hours format.` For hours we use "j" and "H." You can use one or two characters. The lowercase h is used for a 12-hour clock. The uppercase H is a 24-hour clock. `Value h: `Display the hours in one digit if possible. If the hours is greater than 9, it will display two digits. Range is 1-12.`Value hh: `Display the hours in two digits always, even if the hour is one digit. The range here will be 01-12.`Value H: `This represents the hours in a range of 0-23, which is called military time in some parts of the world.`Value HH: `This returns the hours in a range of 00-23. With a single H, there is always a leading zero if the number is one digit.`Day format.` For days we use one to four d chars. One "d" and "dd" indicate the day of the month, while "ddd" and "dddd" indicate the day of the week, in a word. `Value d: `Use this to specify the numeric value for the day of the month. It will be one or two digits long.`Value dd: `This is the same as a single d, except there are always two digits, with a leading 0 prepended if necessary.`Value ddd: `This displays a three-letter string that indicates the current day of the week.`Value dddd: `This displays the full string for the day of the week. An example would be "Saturday."`Month format.` The month is formatted with an uppercase M. One and two Ms display numeric representations. Three and four Ms display string representations. `M, MM: `These display the months in numeric form. One M does not have a leading zero on it. Two Ms have a leading zero.`MMM: `This displays the three-letter form of the month represented in the DateTime (like "Jan").`MMMM: `This displays the full month string, properly capitalized. An example is "January".`Year format.` The year format uses the lowercase y letter. We can put one to five characters for the year. It is unlikely we will need five characters. `For year strings, we use the values "y" through "yyyyy". These display the year to different digits.`However: `In your programs, you won't need three digits for the year (yyy), or five.`Misc.` Even more DateTime formatting characters are available. You can change how AM and PM are displayed. You can display AD and BC. You can show the UTC offset and even display time zones. `Value t: `Use the lowercase t to indicate A, when the time is in the AM, and P, for when the time is in PM.`Value tt: `Use two lowercase tts to display the full AM or PM string. You will normally want this for displaying the string to a user.`Value gg: `Use this to display AD on your date. It is unlikely that this will be BC in most programs.`Value k: `Use this to display time zone information. This is often not needed in programs.`Values z, zz, zzz: `These represent the offset from the UTC time on the local operating system.`Colon and slash: `The colon is the time separator ":". The slash the date separator "/".`Complete day.` Often we need to display the complete day of the week, and the four ds together will do this. With Console.WriteLine, we print all seven day strings we get from the dddd. `Console.WriteLine `console`Three-letter days.` We can display the day of the week in a three-letter form. Here we see a simple program that does this. Results vary based on the current language. `Era.` We can display the date with the era or period—usually AD or BC. It is unlikely that you will need to use BC, except in a rare theoretical application. Here is what two gs will print. `Month.` Programs have different formatting requirements for month names. Sometimes, the first three letters of the name are needed. This helps in tabular or spreadsheet displays. `DateTime.Month `datetime-month`AM, PM.` When you specify one t, you can get the first letter of the AM or PM string. This is equivalent to using Substring or getting the first char of the tt string. `There is a space at the end of the format string—the value "t" can mean something else in the format string.`Next: `We show a program that gets the string AM or PM in DateTime ToString code.`There are no periods in the output of tt. If you require periods in your AM or PM, you would have to manipulate the string.`Year.` We can vary the number of digits displayed in the year string. We will want to use y, yy, or yyyy for our programs. But five ys is also possible. `Sometimes: `Two ys is useful for a user-oriented program, but for back-end code, we will want to use four ys.`Many DateTime formats` can be used. We covered single-letter preset format strings. And we handled more complicated, custom strings with character codes.

VX^231:DQbJA%.y.{P|y{|'O|{ajPDQbJA%.y.P|y'O|PEDQbJA%.y.'O'O'O'O'O'O'O'O'O'O'O'O'O'O'O'O'ODQbJA%.y.'O{j'O{j'O{j'O{j'OOOOOODQD?Q5bJA%.y.{jc|PMyOayMy[{'.ObDQbJA%.yq.{5aVP''DQbJA%.y.wiy'OyDQbJA%.y.wiy'Oy['.ObDQbJA%.y.wiy'OyDQbJA%.y.'O'O'O'O'O XXXXX { VXV{ VV^X^ timeXX.Now;^VVV XUse current time. VV^X XmatX^"MMM ddd d HH:mm yyyy"^;^ XUse this Xmat. VV^Xtime.^ToX^(Xmat));^ XXXconsole. V^} } ^ Feb Tue 21 13:15 2017 ^Format X pattern^ MMMV display three-letter month dddV display three-letter day of the WEEK dV display day of the MONTH HHV display two-digit hours on 24-hour scale mmV display two-digit minutes yyyyVdisplay four-digit year^ XXXXX { VXV{ VV^X^ timeXX.Now; VVX XmatX^"M d h:mm yy"^; VVXtime.^ToX^(Xmat)); V} } ^ 2 27 11:48 09 ^Format X pattern^ MV display one-digit month X dV display one-digit day of the month hV display one-digit hour on 12-hour scale mmV display two-digit minutes yyV display two-digit year^ XXXXX { VXV{ VV^X^ nowXX.Now; VVXnow.^ToX^(^"d"^)); VVXnow.ToX("D")); VVXnow.ToX("f")); VVXnow.ToX("F")); VVXnow.ToX("g")); VVXnow.ToX("G")); VVXnow.ToX("m")); VVXnow.ToX("M")); VVXnow.ToX("o")); VVXnow.ToX("O")); VVXnow.ToX("s")); VVXnow.ToX("t")); VVXnow.ToX("T")); VVXnow.ToX("u")); VVXnow.ToX("U")); VVXnow.ToX("y")); VVXnow.ToX("Y")); V} } ^ dV2/27/2009 DVFriday, February 27, 2009 fVFriday, February 27, 2009 12:11 PM FVFriday, February 27, 2009 12:12:22 PM gV2/27/2009 12:12 PM GV2/27/2009 12:12:22 PM mVFebruary 27 MVFebruary 27 oV2009-02-27T12:12:22.1020000-08:00 OV2009-02-27T12:12:22.1020000-08:00 sV2009-02-27T12:12:22 tV12:12 PM TV12:12:22 PM uV2009-02-27 12:12:22Z UVFriday, February 27, 2009 8:12:22 PM yVFebruary, 2009 YVFebruary, 2009^ XXXXX { VXV{ VV^X^ nowXX.Now; VVXnow.ToLongDateX());^ XEquivalentXD. VV^Xnow.ToLongTimeX());^ XEquivalentXT. VV^Xnow.ToShortDateX());^ XEquivalentXd. VV^Xnow.ToShortTimeX());^ XEquivalentXt. VV^Xnow.ToX()); V} } ^ ToLongDateXV Friday, February 27, 2009 ToLongTimeXV 12:16:59 PM ToShortDateXV2/27/2009 ToShortTimeXV12:16 PM ToXVVV 2/27/2009 12:16:59 PM^ XX; XXX.XXXX { VXV{ VV^X^ nowXX.Now;^ VVXUse space after sXaXone-char date Xmat. VV^X XXnow.^ToX^(^"s "^); VVXLine(^$"{now} [s]X{X}"^); V} } ^ 12/5/2015 2:04:^17^ PM [s]X^17^Statement that Xs hours: C#^ ^XAssume it is 1 PM. ^XX.Now.ToX(^"HH"^))X^ 13^ XXXXX { VXV{ VV^X^ timeXXX(2000, 1, 1);^ VVXX.XLineXX.Format can handle dates. VV^X^"Two letters: {0:ddd}"^, time); VVX^"Three letters: {0:dddd}"^, time); V} } ^ Two letters: Sat Three letters: Saturday^ XXXXX { VXV{ VVX nowXX.Today; VVX(XiX0; i < 7; i++) VV{ VVVXnow.^ToX^(^"dddd"^)); VVVnowXnow.^AddDays^(1); VV} V} } ^ Thursday Friday Saturday Sunday Monday Tuesday Wednesday^ XXXXX { VXV{ VVX nowXX.Today; VVX(XiX0; i < 7; i++) VV{ VVVXnow.^ToX^(^"ddd"^)); VVVnowXnow.^AddDays^(1); VV} V} } ^ Thu Fri Sat Sun Mon Tue Wed^Statement that Xs era: C#^ XX.Now.ToX(^"gg"^))X^ A.D.^ XXXXX { VXV{ VVX nowXX.Now; VVX(XiX0; i < 2; i++) VV{ VVVXnow.^ToX^(^"tt "^)); VVVnowXnow.^AddHours^(12); VV} V} } ^ PM AM^ XXXXX { VXV{ VVX nowXX.Now; VVXnow.^ToX^(^"y "^)); VVXnow.ToX(^"yy"^)); VVXnow.ToX(^"yyy"^)); VVXnow.ToX(^"yyyy"^)); VVXnow.ToX(^"yyyyy"^)); V} } ^ 9 09 2009 2009 02009^

*_`-`X\1*2.DateTime formatdifferent formattests formatsToString methodss formatddd and ddddshows day stringstests daysdisplays AM and PMdisplays years