Format of GMT time in C # time format

Source: Internet
Author: User
Tags iso 8601 truncated

GMT: Hotell gyllene Geten Standard Time
Beijing Time =gmt time + 8 hours
Datatime nowdate = Datatime.now;
Nowdate.tostring ("R"); Effect: Wed, 16:24:33 GMT

Explanation of the parameters:
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 General (short date and long time)
M, M Monthdaypattern
R, R Rfc1123pattern
s use local time Sortabledatetimepattern (based on ISO 8601)
T Shorttimepattern
T Longtimepattern
U universalsortabledatetimepattern format for displaying the Universal Time
U use the full date and time of the universal Time (long date and long time)
Y, y Yearmonthpattern





The following table lists the patterns that can be combined to construct their own defined patterns
========================================
These patterns are distinguished by uppercase and lowercase. For example, "MM" is recognized, but "MM" is not recognized. Assume that you define a pattern that includes whitespace characters or characters enclosed in a single argument. The output string page will also include these characters. A character that is not defined as part of the format pattern or is not defined as a format character is copied by its original meaning.


Format Pattern Description:
A day in the D month. One-digit date has no leading zeros.
DD a day of the month.

A one-digit date has a leading zero.


The abbreviated name of the day of the DDD week, defined in Abbreviateddaynames.


dddd the full name of the day of the week, as defined in DayNames.
M-month number.

One-digit month has no leading zeros.
MM month number.

One-digit month has a leading zero.


Abbreviated name of the MMM month, defined in AbbreviatedMonthNames.
The full name of the MMMM month, as defined in MonthNames.
Y does not include the year of the era.

If the year that does not include the era is less than 10, the year is displayed without leading zeros.
YY does not include the year of the era. If the year that does not include the era is less than 10, the year with leading zeros is displayed.


The YYYY contains the four-digit year of the era.
GG period or ERA. Assuming that the date to be formatted does not have an associated period or era string, the pattern is ignored.


H 12 Hour hour system. One-digit hours do not have leading zeros.


HH 12-hour hour.

One-digit hours have leading zeros.
H 24 hour hour system. One-digit hours do not have leading zeros.


HH 24-hour hour.

One-digit hours have leading zeros.


M minutes.

A single-digit number of minutes does not have a leading zero.
MM minutes. A single-digit number of minutes 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 of one digit has a leading zero.
The fractional precision of the F-second is one digit. The remaining digits are truncated.
The fractional precision of the FF seconds is two bits.

The remaining digits are truncated.
The fractional precision of FFF seconds is three bits. The remaining digits are truncated.


The fractional precision of ffff seconds is four bits. The remaining digits are truncated.
The fractional precision of fffff seconds is five bits.

The remaining digits are truncated.


The fractional precision of ffffff seconds is six bits.

The remaining digits are truncated.
The fractional precision of fffffff seconds is seven bits. The remaining digits are truncated.
t the am/pm defined in AMDesignator or PMDesignator indicates the first character of the item (assuming it exists).
The AM/PM indicator (assuming existence) that the TT defines in AMDesignator or PMDesignator.
The Z Time zone offset ("+" or "-" followed by hours only).

One-digit hours do not have leading zeros.

For example, the Pacific Standard Time is "-8".


ZZ Time zone offset ("+" or "-" followed by hours only). One-digit hours have leading zeros.

Like what. Pacific Standard Time is "-08".
The ZZZ Full time zone offset ("+" or "-" followed by hours and minutes).

The number of hours and minutes of a single digit has a leading zero.

For example, the Pacific Standard Time is " -08:00".
: The default time delimiter defined in TimeSeparator.
/The default date delimiter defined in DateSeparator.
% c is the format pattern (assuming that it is used separately).

The "%" character can be omitted if the format pattern is merged with a literal character or other format pattern.


C is a random character in C. Displays the characters as they are originally defined. The backslash character to display. Please use "\ \".




Only the format patterns listed in the second table above are used to create their own definition patterns. The standard format characters listed in the first table cannot be used to create your own definition pattern. The length of your own definition pattern is at least two characters. Like what.
DateTime.ToString ("D") returns a DateTime value; "D" is a standard short date pattern.
DateTime.ToString ("%d") returns the day of the month; "%d" is its own definition pattern.
DateTime.ToString ("D") returns the day of the month followed by a white space character. "D" is a self-defining pattern.


More convenient is that the above can be any combination of parameters, and will not be wrong, try more, will definitely find the time format you want
To get the time in this format for June 2005
To write like this:
Date. ToString ("yyyy mm month", Datetimeformatinfo.invariantinfo)
So the analogy.


The following is a list of some of the detailed date formatting uses in asp:
============================================
1. Bind timed Format Date method:
2. Data controls such as Datagrid/datalist format Date method:
E.item.cell[0]. Text = Convert.todatetime (e.item.cell[0]. Text). ToShortDateString ();

3. Use the string class to convert the date display format:
String.Format ("Yyyy-mm-dd", yourdatetime);


4. Convert date display format with convert method:
Convert.todatetime ("2005-8-23"). ToString ("YyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo); Support for traditional databases


5. Convert the date display format directly with the ToString method:
DateTime.Now.ToString ("Yyyymmddhhmmss");
DateTime.Now.ToString ("Yyyy/mm/dd hh:mm:ss")


6. Only show year DataBinder.Eval (Container.DataItem, "StartTime", "{0:yyyy-m}")

7. Display all the time, including: Month Day seconds dataformatstring= ' {0:yyyy-mm-dd HH24:mm:ss} ' > output dates in different formats with datetime.tostring (string format)


The DateTime.ToString () function has four overloads. Generally used more is the one that does not take the number of references.

As everyone knows, datetime.tostring (string format) is more powerful and can output dates in different formats. Here are a list of some of the circumstances for everyone to participate in the test. Some of them are not listed on MSDN.


1. Y represents the year. Note that it is lowercase y. Uppercase y does not represent the year.
2. m represents the month.


3. D represents the date, noting that D does not mean anything.


4. h or H represents hours, and H is 12-hour system. H is a 24-hour system.
5. m represents minutes.


6. s represents seconds.

Note that s doesn't mean anything.

Format Output Demo sample


Years


Y
7
String yy = DateTime.Now.ToString ("y-mm")


Yy= "7-05"


Yy
07
String yy = DateTime.Now.ToString ("yy-mm")


Yy= "07-05"


YYY or a lot of other Y
1984
String yy = DateTime.Now.ToString ("yyyy");


Yy= "2007"


Month


M
5.
String mon = DateTime.Parse ("1984-05-09") ToString ("Yyyy-m")


Mon = "1984-5"


Mm
05.
String mon = DateTime.Parse ("1984-05-09") ToString ("MM")


Mon = "05"


MMM
Assume that the Chinese version of the operating system. The output will be: May.


The assumption is an English operating system. Enter the first three letters of the month: May
String mon = DateTime.Parse ("2006-07-01"). ToString ("MMM")


English version of operating system: Jul


Chinese version of the operating system: July


Mmmm or a lot of other m
Assuming the Chinese version of the operating system, it will output: May.


If it is an English operating system, enter the full write of the month
String mon = DateTime.Parse ("2006-07-01"). ToString ("MMM")


English version of operating system: July


Chinese version of the operating system: July


Date or day of the week


D
9
String dd= datetime.parse ("1984-05-09") ToString ("D")


Dd= "9"




Dd
09
String dd= datetime.parse ("1984-05-09") ToString ("DD")


dd= "09"


Ddd
If it is a Chinese version of the operating system, it will output weeks, such as Wednesday.


If it is an English operating system, the output Week is abbreviated:


Wed
string dd = DateTime.Parse ("2006-07-01"). ToString ("ddd")


English version of operating system: Wed


Chinese version of the operating system: Wednesday


dddd or a lot of other D
If it is the Chinese version of the operating system, the week will be output. As in Wednesday.

.


If it is an English operating system, the output week:


Wednesday
string dd = DateTime.Parse ("2006-07-01"). ToString ("dddd")


English version of operating system: Wednesday


Chinese version of the operating system: Wednesday


Hours


H
Hour Range: 1-12
string hh = DateTime.Now.ToString ("h");


HH = 8


HH or a lot of other H
Hour Range: 1-12
string hh = DateTime.Now.ToString ("hh");


HH = 08


H
Hour Range: 0-23
string hh = DateTime.Now.ToString ("yyyy-h");


HH = 2006-8


HH or a lot of other H
Hour Range: 0-23
string hh = DateTime.Now.ToString ("yyyy-hh");


HH = 2006-08


string hh = Datetime.pare ("2006-7-4 18:00:00"). ToString ("yyyy-hh");


HH = 2006-18


Minutes


M
6
string mm = DateTime.Now.ToString ("yyyy-mm-dd-m");


MM = "2006-07-01-6";


MM or a lot of other m
06
string mm = DateTime.Now.ToString ("yyyy-mm-dd-mm");


MM = "2006-07-01-06";


Seconds


S
6
string mm = DateTime.Now.ToString ("Yyyy-mm-dd-s");


MM = "2006-07-01-6";


SS or a lot of other s
06
string mm = DateTime.Now.ToString ("Yyyy-mm-dd-ss");


MM = "2006-07-01-06";

Format of GMT time in C # time format

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.