C #/. net Time Format Conversion

Source: Internet
Author: User
Tags net time

0: Time Format Conversion

System. DateTime currentTime = new System. DateTime ();

1. The value is the current year, month, day, hour, minute, and second.

CurrentTime = System. DateTime. Now;

2. Select the current year.

Int Year = currentTime. Year;

3. Select the current month.

Int Month = currentTime. Month;

4. Select the current day.

Int Day = currentTime. Day;

5. Obtain the current time

Int = currentTime. Hour;

6. Obtain the current score

Int = currentTime. Minute;

7. Take the current second

Int Second = currentTime. Second;

8 takes the current millisecond

Int Millisecond = currentTime. Millisecond;

9 display Chinese date -- year, month, day

String strY = currentTime. ToString ("f"); // seconds not displayed

10. Use Chinese date to display _ year and month

String strYM = currentTime. ToString ("y ");

11. Use Chinese date to display _ month/day

String strMD = currentTime. ToString ("m ");

12 Chinese year, month, and day

String strYMD = currentTime. ToString ("D ");

13. Take the current time, in the format

String strT = currentTime. ToString ("t ");

14. Take the current time in the format of T14: 46: 48.

String strT = currentTime. ToString ("s ");

15. Obtain the current time in the format of 2003-09-23 14: 48: 30Z.

String strT = currentTime. ToString ("u ");

16. The current time. format:

String strT = currentTime. ToString ("g"); www.2cto.com

17. Take the current time, in the format of Tue, 23 Sep 2003 14:52:40 GMT

String strT = currentTime. ToString ("r ");

18 get the date and time of the current time n days later

DateTime newDay = DateTime. Now. AddDays (100 );


Author: YYYu

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.