Format of GMT time in C # time format

Source: Internet
Author: User
Tags iso 8601 local time

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

Parameter explanation:
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 a custom pattern
========================================
These patterns are case-sensitive, for example, "MM" is recognized, but "MM" is not recognized. If the custom pattern contains white space characters or characters enclosed in single quotation marks, the output string page will also contain these characters. Characters that are not defined as part of the format pattern or that are not defined as format characters are copied verbatim.


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 contain the year of the era. If the year that does not contain an era is less than 10, the year is displayed without leading zeros.
YY does not contain the year of the era. If the year that does not contain an era is less than 10, the year with leading zeros is displayed.
The YYYY includes the four-digit year of the era.
GG period or ERA. If 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, if one exists.
The AM/PM indicated by the TT in AMDesignator or PMDesignator (if present).
The Z Time zone offset ("+" or "-" followed by hours only). One-digit hours do not have leading zeros. For example, Pacific Standard Time is "-8".
ZZ Time zone offset ("+" or "-" followed by hours only). One-digit hours have leading zeros. For example, 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, 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 pattern (if used alone). You can omit the "%" character if the format pattern is merged with literal characters or other format patterns.
\ c where c is any character. Displays the characters as they are originally defined. To display a backslash character, use "\ \".


Only the format patterns listed in the second table above can be used to create custom patterns, and the standard format characters listed in the first table cannot be used to create custom patterns. The custom pattern is at least two characters long;
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 a custom pattern.
DateTime.ToString ("D") returns the day of the month followed by a blank character, and "D" is a custom pattern.


More convenient is that the above parameters can be arbitrarily combined, 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
It can be written like this:
Date. ToString ("yyyy mm month", Datetimeformatinfo.invariantinfo)
So the analogy.


The following is a list of some of the specific 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 parts of 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 much is the one without parameters. As everyone knows, datetime.tostring (string format) is more powerful and can output dates in different formats. Some of the following are listed for your reference. Some of them are not listed on MSDN.


1. Y represents the year, note is lowercase y, and 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, H is 12 hours, H is 24 hours.
5. m represents minutes.
6. s represents seconds. Note that s doesn't mean anything.

Sample format output


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 more 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
If it is the Chinese version of the operating system, it will be output: May.


If it 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 more M
If it is the Chinese version of the operating system, it will be 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 the Chinese version of the operating system, it will output the week, 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 more D
If it is the Chinese version of the operating system, it will output the week, such as 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 more 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 more 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 more 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 more 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.