C # date formatting,

Source: Internet
Author: User

C # date formatting,

Generally, the date format of our computer is yyyy-M-d, which is the default format of the system, but sometimes, to display, we may only display the year and month yyyy-M, in this case, the date displayed by the DatePicker control is also yyyy-M,

Therefore, the date obtained through the text attribute of the DatePicker control is only a year and a month, but this is not what we want, we need a day, so no matter how the computer is set, we all need to set the DatePicker control to the format we need.

In this case, the date format is required,

The formatted code is

Thread. currentThread. currentCulture = new CultureInfo ("zh-CN"); Thread. currentThread. currentCulture = (CultureInfo) Thread. currentThread. currentCulture. clone (); Thread. currentThread. currentCulture. dateTimeFormat. shortDatePattern = "yyyy-MM-dd ";

You only need to put the three lines of code in the constructor. If you need different formats, replace yyyy-MM-dd.

 

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.