Time conversion in C #

Source: Internet
Author: User
Tags iso 8601

In C #, The tostring () method of datetime is used. This method has six reloads. Here, tostring (string format) is used)
Format description:
Format character Association attributes/Description
D shortdatepattern
D longdatepattern
F complete date and time (long date and short time)
F fulldatetimepattern (long date and long time)
G regular (short date and short time)
G regular (short date and long time)
M, M monthdaypattern
R, R rfc1123pattern
S uses sortabledatetimepattern of the local time (based on ISO 8601)
T shorttimepattern
T longtimepattern
U universalsortabledatetimepattern is used to display the format of common time
U uses the complete date and time of the general time (long date and long time)
Y, y yearmonthpattern
 
The following table lists the modes that can be merged to build a custom mode. These modes are case sensitive. For example, "mm" is recognized, but "mm" is not recognized ". If the custom mode contains white space characters or characters enclosed by single quotes, the output string page also contains these characters. Characters that are not defined as part of the format or are not defined as formatted characters are copied according to their original meaning.
 
Format description
D. A single-digit date has no leading zero.
A day in DD month. A single-digit date has a leading zero.
The abbreviation of a day in DDD Week, which is defined in abbreviateddaynames.
The full name of the Day of the dddd Week, which is defined in daynames.
M month number. One-digit month does not have a leading zero.
Mm Month number. A single-digit month has a leading zero.
The abbreviated name of the mmm month, which is defined in abbreviatedmonthnames.
The full name of the mmmm month, which is defined in monthnames.
Y does not contain the year of the epoch. If the year that does not contain the epoch is less than 10, the year that does not have the leading zero is displayed.
YY does not contain the year of the epoch. If the year that does not contain the epoch is less than 10, the year with the leading zero is displayed.
Yyyy includes the four-digit year of the epoch.
Gg period or epoch. This mode is ignored if the date to be formatted does not have an associated period or epoch string.
H 12-Hour. One-digit hours do not have a leading zero.
The hour in HH 12-hour format. The number of hours in a single digit has a leading zero.
H In 24-hour format. One-digit hours do not have a leading zero.
The hour in the 24-hour format. The number of hours in a single digit has a leading zero.
M minutes. The number of minutes in a single digit does not start with zero.
MM minutes. The number of minutes in a single digit has a leading zero.
S seconds. The number of seconds in a single digit does not have a leading zero.
SS seconds. The number of seconds in a single digit has a leading zero.
The decimal precision of second F is one digit. The remaining numbers are truncated.
The decimal precision of FF seconds is two digits. The remaining numbers are truncated.
The decimal precision of fff seconds is three. The remaining numbers are truncated.
The decimal precision of FFFF seconds is four digits. The remaining numbers are truncated.
The decimal precision of fffff seconds is five digits. The remaining numbers are truncated.
The decimal precision of ffffff seconds is six digits. The remaining numbers are truncated.
The decimal precision of fffff seconds is seven digits. The remaining numbers are truncated.
T the first character (if any) of the AM/PM indicator defined in amdesignator or pmdesignator ).
The AM/PM indicator defined by TT in amdesignator or pmdesignator (if any ).
Z Time Zone offset ("+" or "-" is followed by only the hour ). One-digit hours do not have a leading zero. For example, the Standard Time in the Pacific is-8 ".
ZZ Time Zone offset ("+" or "-" is followed by only the hour ). The number of hours in a single digit has a leading zero. For example, the Standard Time in the Pacific is-08 ".
The full time zone offset of ZZZ ("+" or "-" followed by hours and minutes ). The number of hours and minutes in a single digit has a leading zero. For example, the Pacific Standard Time is ".
: Default Time delimiter defined in timeseparator.
/Default date delimiter defined in dateseparator.
% C where c is the Format mode (if used separately ). If the Format mode is combined with the original and other formats, the "%" character can be omitted.
C, where C is any character. Display characters according to the original meaning. To display the backslash character, use "".

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.