Datetime. tostring Method

Source: Internet
Author: User

Today, we know that datetime. tostring has so many other methods. With this example, it is much easier to get time strings of different formats.

Using system;
Using system. Globalization;

Public class mainclass {
Public static void main (string [] ARGs ){
Datetime dt = datetime. now;
String [] format = {
"D", "D ",
"F", "F ",
"G", "g ",
"M ",
"R ",
"S ",
"T", "T ",
"U", "U ",
"Y ",
"Dddd, Mmmm dd YYYY ",
"DDD, mmm D/" '/"YY ",
"Dddd, Mmmm dd ",
"M/YY ",
"DD-mm-yy ",
};
String date;
For (INT I = 0; I <format. length; I ++ ){
Date = DT. tostring (Format [I], datetimeformatinfo. invariantinfo );
Console. writeline (string. Concat (Format [I], ":", date ));
}


/** output.

* D: 08/17/2000
* D: Thursday, August 17,200 0
* F: Thursday, august 17,200 0 16:32:32
* F: Thursday, August 17,200 0 16:32:32
* G: 08/17/2000
* G: 08/17/2000
* m: august 17
* r: Thu, 17 Aug 2000 23:32:32 GMT
* s: 2000-08-17t16: 32: 32
* T: 16: 32
* T: 16: 32: 32
* u: 2000-08-17 23: 32: 32z
* u: Thursday, august 17,200 0 23:32:32
* Y: August, 2000
* dddd, Mmmm dd yyyy: Thursday, August 17 2000
* DDD, mmm D "'" YY: Thu, Aug 17' 00
* dddd, Mmmm DD: Thursday, August 17
* m/YY: 8/00
* DD-mm-yy: 17-08-00
*/
}< BR >}

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.