Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the formatting display methods of Asp.net date string

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "what are the Asp.net date string formatting display methods", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "what are the Asp.net date string formatting display methods"!

Here will be used: DateTime.ToString 's method (String,IFormatProvider)

Example:

The following is a reference clip:

UsingSystem

UsingSystem.Globalization

Stringformat= "D"

DateTimedate=DataTime.Now

Response.Write (date.ToString (format,DateTimeFormatInfo.InvariantInfo))

Result output

Thursday,June16,2006

Detailed usage of the parameters in format format is listed here.

=

Format character association attribute / description

DShortDatePattern

DLongDatePattern

F full date and time (long date and short time)

FFullDateTimePattern (long date and long time)

G General (short date and short time)

G routine (short date and long time)

M 、 MMonthDayPattern

R 、 RRFC1123Pattern

S uses local time SortableDateTimePattern (based on ISO8601)

TShortTimePattern

TLongTimePattern

The format used by uUniversalSortableDateTimePattern to display universal time

U uses the full date and time of universal time (long date and long time)

Y 、 YYearmonthPattern

The following table lists the patterns that can be merged to construct custom patterns

= =

These patterns are case-sensitive; for example, recognize "MM" but not "mm". If the custom mode contains blank characters or characters enclosed in single quotation marks, the output string page will also contain those characters. Characters that are not defined as part of a format pattern or are not defined as format characters are copied in their original meaning.

Format mode description:

One day in the d-month. A single-digit date does not have a leading zero.

What are the formatting display methods of Asp.net date string

One day in the dd month. A single-digit date has a leading zero.

The abbreviated name of the day of the week in ddd, defined in AbbreviatedDayNames.

The full name of the day of the week in dddd, defined in DayNames.

M month number. Single-digit months have no leading zeros.

MM month number. A single-digit month has a leading zero.

The abbreviated name of the MMM month, defined in AbbreviatedMonthNames.

The full name of the MMMM month, defined in MonthNames.

Y does not contain the year of the era. If the year that does not include an era is less than 10, the year without a leading zero is displayed.

Yy does not contain the year of the era. If the year that does not include an era is less than 10, the year with a leading zero is displayed.

Yyyy includes the four-digit year of the era.

Gg period or era. If the date you want to format does not have an associated period or era string, the pattern is ignored.

H22 hourly hours. Single-digit hours have no leading zeros.

Hours of hh22 hours. Single-digit hours have leading zeros.

H24 hourly hours. Single-digit hours have no leading zeros.

Hours of HH24 hours. Single-digit hours have leading zeros.

M minutes. There is no leading zero in single-digit minutes.

Mm minutes. Single-digit minutes have a leading zero.

S seconds. There is no leading zero for single-digit seconds.

Ss seconds. Single-digit seconds have a leading zero.

The decimal precision of f seconds is one digit. The rest of the figures were truncated.

The decimal precision of ff seconds is two digits. The rest of the figures were truncated.

The decimal precision of fff seconds is three digits. The rest of the figures were truncated.

The decimal precision of ffff seconds is four digits. The rest of the figures were truncated.

The decimal precision of fffff seconds is five digits. The rest of the figures were truncated.

The decimal precision of ffffff seconds is six digits. The rest of the figures were truncated.

The decimal precision of fffffff seconds is seven places. The rest of the figures were truncated.

The first character (if present) of the AM/PM indicator defined in AMDesignator or PMDesignator.

The AM/PM indicator entry defined by tt in AMDesignator or PMDesignator, if it exists.

Z time zone offset ("+" or "-" followed by hours only). Single-digit hours have no leading zeros. For example, Pacific Standard time is "- 8".

Zz time zone offset ("+" or "-" followed by hours only). Single-digit hours have leading zeros. For example, Pacific Standard time is "- 08".

Zzz full time zone offset ("+" or "-" followed by hours and minutes). Single-digit hours and minutes have leading zeros. For example, Pacific Standard time is-08:00.

The default time delimiter defined in TimeSeparator

/ default date delimiter defined in DateSeparator.

% c where c is the format mode (if used alone). If the format pattern is merged with literal characters or other format patterns, the'% 'character can be omitted.

\ c where c is any character. Displays characters as they are intended. To display the backslash character, use "\".

Only the format patterns listed in the second table above can be used to create custom schemas; the standard format characters listed in the first table cannot be used to create custom schemas. The length of a custom mode is at least two characters; for example

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

DateTime.ToString ("d") returns a day of the month; "d" is a custom mode.

DateTime.ToString ("d") returns the day of the month followed by a white space character; "d" is the custom mode.

At this point, I believe you have a deeper understanding of "what are the Asp.net date string formatting display methods". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report