C # datetime string

Source: Internet
Author: User

I don't have any new discoveries. It's just because I am a software developer and I don't have a lot of basic knowledge. I hope I can help you with it:
1. datetime comparison:
For example, datetime dt1 and dt2 can be compared directly using if (dt1> dt2). if it is converted to a string, it is unnecessary;
Of course, you can convert DateTime. Today. Date. ToOADate () to a decimal number for comparison;
If the time is saved as a string and it is not tightened, you can use DateTime dt = DateTime. parse ("2012/12/02"); to convert to the time format for comparison, it is not necessary to compare the year first, in the comparison month, in the comparison Day;
If you want to display the date in the desired format, you can use System. dateTime. today. date. toString ("yyMMdd");, where yyyy is a year (the last two digits can be expressed by yy), MM (must be capitalized) is a month, and dd is a day.
2. sometimes (especially when you need to generate a sequential number), you need to convert the number into two digits. Of course, you can write a function by yourself to determine the size, or the number of characters to implement:
For example, convert 1 to 01: string. Format ("{0: 00}", 1 );
Change 1 to 001: string. Format ("{0: 000}", 1 );
Change 001,002 to: string. Format ("{0: 000 );

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.