C#datetime and Random

Source: Internet
Author: User

1.DateTime (date)

Defined:

(1). DateTime Variable name = new DateTime (year, month, day, time, minute, second);(year, month, day, time, minute, second type must be int)

(2). DateTime variable name = DateTime. Attribute;

The most commonly used properties are:

Now gets the local time. (most commonly used)

Year gets the part of the middle age. (default value is 1)

Month gets the portion of the date in the months. (default value is 1)

Day gets the part of the date. (default value is 1)

Hour gets the part of the date. (default value is 1)

Minute gets the part of the date that is divided. (default value is 1)

Second gets the part of the date in seconds. (default value is 1)

The most common way:

DateTime dt = DateTime.Now;

int i = dt. year;

Console.WriteLine (i);

2.Random (random number)

Grammar:

Random rd = new random ();(define a single number)

int i;

(1). I= Rd. Next (); randomly generates a number.

(2). i = Rd. Next (100); randomly produces a number less than 100.

(3). I= Rd. Naxt (100,1000) randomly generates a number greater than 100 and less than 1000.

C#datetime and Random

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.