C time format of Datetime

  • 2020-05-19 04:44:08
  • OfStack

Datetime.ToString(String, IFormatProvider)

Parameter format format detailed usage:

Format characters Associated properties/descriptions d ShortDatePattern D LongDatePattern f Full date and time (long date and short time) F FullDateTimePattern (long date and long time) g General (short date and short time) G Routine (short date and long time) m, M MonthDayPattern r, R RFC1123Pattern s Use SortableDateTimePattern local time (based on ISO 8601) t ShortTimePattern T LongTimePattern u UniversalSortableDateTimePattern is a format for displaying common times U Full date and time using common time (long date and long time) y, Y YearMonthPattern

The following table lists patterns that can be combined to construct custom patterns. These patterns are case sensitive; For example, identify "MM" but not "mm". If the custom pattern contains white space characters or characters enclosed in single quotes, the output string page will also contain these characters. A character that is not defined as part 1 of a format pattern or as a format character is copied in its original meaning.

Format pattern instructions d A day in the month. A 1-digit date has no leading zero. dd A day in the month. A 1-digit date has a leading zero. ddd The abbreviation of a day of the week, as defined in AbbreviatedDayNames. dddd The full name of a day of the week, defined in DayNames. M Monthly figures. One-digit months have no leading zeros. MM Monthly figures. A 1-digit month has a leading zero. MMM The abbreviated name of the month, as defined in AbbreviatedMonthNames. MMMM The full name of the month, defined in MonthNames. y A year that does not contain an era. If the year without epoch is less than 10, the year without leading zero is displayed. yy A year that does not contain an era. If the year without epoch is less than 10, the year with leading zero is displayed. yyyy A year containing four digits of an era. gg A period or epoch. If you want to format a date that does not have an associated period or epoch string, you ignore the pattern. h 12 hours. The number of one-digit hours has no leading zero. hh 12 hours. The number of one-digit hours has a leading zero. H A 24-hour system of hours. The number of one-digit hours has no leading zero. HH A 24-hour system of hours. The number of one-digit hours has a leading zero. m Minutes, 1 digit minutes without leading zero. mm Minutes, the number of minutes of one digit has one leading zero. s Seconds, the number of seconds of one digit without leading zero. ss Seconds, the number of seconds of one digit has one leading zero. f The decimal precision of seconds is 1 bit. The remaining Numbers are truncated. ff The decimal precision of seconds is two digits. The remaining Numbers are truncated. fff The decimal precision of seconds is 3 digits. The remaining Numbers are truncated. ffff The decimal precision of seconds is 4 digits. The remaining Numbers are truncated. fffff The decimal precision of seconds is 5 digits. The remaining Numbers are truncated. ffffff The decimal precision of seconds is 6 digits. The remaining Numbers are truncated. fffffff The decimal precision of seconds is 7 digits. The remaining Numbers are truncated. t The first character (if present) of the AM/PM indicator defined in AMDesignator or PMDesignator. tt The AM/PM indicator, if present, defined in AMDesignator or PMDesignator. z Time zone offset (" + "or" - "followed only by hours). The number of one-digit hours has no leading zero. Pacific standard time, for example, is "-8". zz Time zone offset (" + "or" - "followed only by hours). The number of one-digit hours has a leading zero. For example, Pacific standard time is "-08". zzz Full time zone offset (hours and minutes followed by "+" or "-"). The number of hours and minutes of one digit has a leading zero. For example, Pacific standard time is "-08:00". : The default time delimiter defined in TimeSeparator. / The default date delimiter defined in DateSeparator. %c Where c is the format mode (if used separately). If the format pattern merges with the literal character or another format pattern, the '%' character can be omitted. c Where c is an arbitrary character. Display characters as they appear. To display backslash characters, use "\".

Only the format schema listed in table 2 above can be used to create a custom schema; The standard format characters listed in table 1 cannot be used to create custom schemas. The length of a custom pattern is at least two characters. For example,

DateTime.ToString ("d") returns the DateTime value; "d" is the standard short date mode.

DateTime.ToString("%d") returns to a day in the month; "%d" is a custom pattern.

DateTime.ToString ("d ") returns a day in the month followed by a blank character; "d" is a custom pattern.


Related articles: