10-19c# Foundation--fourth category (2) Focus

Source: Internet
Author: User
Tags local time

Type:

First, the number

1) math.ceiling () (denotes rounding). );//As long as there is a value after the decimal point, go forward one, take the upper limit.

string s = Console.ReadLine ();

Double D = double.parse (s);

D = math.ceiling (d);

D = Math.floor (d);//returns the largest integer less than or equal to the specified double-precision floating-point number; when odd, the decimal point has 0.5, returns the carry, when the number is even, after the decimal point has 0.5, indicates the position, after the decimal point all, takes the lower limit.

Console.Write (d);

Console.ReadLine ();

After execution:

2) Math.floor ());//returns the largest integer less than or equal to the specified double-precision floating-point number;

Note: When an odd number, the decimal point has 0.5, returns the carry, when is even, after the decimal point has 0.5, indicates the place, after the decimal point all, takes the lower limit.

string s = Console.ReadLine ();

Double D = double.parse (s);

D = Math.floor (d);

Console.Write (d);

Console.ReadLine ();

After execution:

3) math.sqrt ();

4) math.pl (), indicating Pi.

Second, date and time type--datetime (emphasis)

1) DateTime dt = new DateTime ();//must be initialized, define a variable; if initialized only, no value is assigned, the computer automatically starts from the default minimum month day; The default time is: January 1, 01 12:00:00 am

sring s = console.readline ();        

DateTime dt = new DateTime ();//

Console.Write (DT);    

Console.ReadLine ();

After execution:

2) DateTime dt = new DateTime ();//You can also create a time

Example: DateTime dt = new DateTime (1998,12,12,12,12,11): Created December 12, 1998 12:12 11 seconds

3) DateTime dt= datetime.now;//Gets the local time on the computer as a class, the property is now, and the value returned is a DateTime type.

Format:

sring s = console.readline ();        

DateTime dt = DateTime.Now;

Console.Write (DT);    

Console.ReadLine ();

After execution:

4). Year;//gets the year on the current computer;

sring s = console.readline ();

DateTime dt=new datetime ();

Dt=datetime.now;

int i = dt. year;

Console.Write (i);

Console.ReadLine ();

After execution:

5). dayofweek;//returns the DayOfWeek type, for example: Sunday; Returns what type to receive with what type;

sring s = console.readline ();

DateTime dt=new datetime ();

DayOfWeek d = dt. DayOfWeek;

Console.Write (d);

Console.ReadLine ();

After execution:

Conversion between a value type and a reference type

6) int i = dt. DayOfYear ();//return date is the day of the year, return int type;

Format:

sring s = console.readline ();

DateTime dt=new datetime ();

int i = dt. DayOfYear ();

Console.Write (i);

Console.ReadLine ();

After execution:

7)//s = dt. ToString ("yyyy mm month DD Day hh" mm minute ss seconds Ms milliseconds ");//Returns a string type that can be formatted after a string:" Yyyy,mm,dd,hh,mm,ss,ms is a surrogate for the month, minute, and minute milliseconds, This format must be used.    

Note: Although the input milliseconds, but in the execution is the computer does not output milliseconds, because there is no setting;

sring s = console.readline ();

DateTime dt=new datetime ();

Dt=datetime.parse (s);

s = dt. ToString ("yyyy mm month DD day hh" mm min ss sec ms milliseconds ");

Console.Write (s);

Console.ReadLine ();

After execution:

Three, time interval type--TimeSpan ()

1) System.TimeSpan time = new TimeSpan (),//timespan is the interval type, maximum plus to day (day), minimum is 100 nanoseconds, cannot Gagnin, month; returns datetime type;

Dt=dt. ADD (time);//can only be a type of interval, parameter is a value of timespan type;

After execution:

2). AddYears (2);//When encountering leap year 29th, the addition is not a leap year display 28th, does not automatically enter the next one months;

After execution:

3)//dt = dt. AddMonths (3);//plus how many months, when the previous month for 31 days beyond the following days, take the current month maximum, do not automatically enter the next month, can not add decimals, parameter is int;

Format:

string s = Console.ReadLine ();
DateTime dt = new DateTime ();

DT = DateTime.Parse (s);
DT = dt. AddMonths (3);
Console.Write (DT);
Console.ReadLine ();

After execution:

4)//dt = dt. AddDays (1.2);//Plus how many days, the parameter is a double type of value

After execution:

5)//dt = dt. AddHours (1.2);//plus the number of hours, the argument is double

Enter an ordinary date:

Enter a special month:

Exercise 1: Enter the year to determine if it is leap years:

Exercise 2: Determine whether the date entered is correct;

10-19c# Foundation--fourth category (2) Focus

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.