C # conversion from date to string

Source: Internet
Author: User

The following is the original post http://www.cnblogs.com/richinger/articles/113085.html

 

In programming, you often need to convert the date variable into a string.

Convert to strings of different formats

Below are some common conversions and conversion results:

Private void form1_load (Object sender, system. eventargs E)

{

// Textbox1.text = datetime. Now. tostring ("DD/MM/YYYY ");

// Textbox1.text = datetime. Now. dayofyear. tostring ();

Textbox1.text = datetime. Now. tostring ("D ");

Textbox2.text = datetime. Now. tostring ("D ");

Textbox3.text = datetime. Now. tostring ("G ");

Textbox6.text = datetime. Now. tostring ("G ");

Textbox5.text = datetime. Now. tostring ("T ");

Textbox4.text = datetime. Now. tostring ("T ");

Textbox12.text = datetime. Now. tostring ("F ");

Textbox11.text = datetime. Now. tostring ("F ");

Textbox10.text = datetime. Now. tostring ("M ");

Textbox9.text = datetime. Now. tostring ("R ");

Textbox8.text = datetime. Now. tostring ("S ");

Textbox7.text = datetime. Now. tostring ("U ");

Textbox13.text = datetime. Now. tostring ("Y ");

Textbox14.text = datetime. Now. tostring ("Y ");


}

The following is the result of another method conversion:

private void form2_load (Object sender, system. eventargs e)

{< br>
textbox1.text = datetime. now. tostring ("m/D/YYYY");
textbox2.text = datetime. now. tostring ("mm/DD/YY");
textbox3.text = datetime. now. tostring ("D-Mmmm-yy");
textbox6.text = datetime. now. tostring ("ddmmyyyy");
textbox5.text = datetime. now. tostring ("DD, mm, yyyy, YYYY");
textbox4.text = datetime. now. tostring ("mm DD, YYYY");

Textbox12.text = datetime. Now. tostring ("YYYY ");

Textbox11.text = datetime. Now. tostring ("mm Month ");

Textbox10.text = datetime. Now. tostring ("DD ");

Textbox9.text = datetime. Now. tostring ("HH: mm: SS ");

Textbox8.text = datetime. Now. tostring ("m/D/yyyy h: mm ");

Textbox7.text = datetime. Now. tostring ("H: mm: SS ");

}

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.