Datetime

zhaozj2021-02-16  48

DateTime constructor

l In initialization is the specified scale PUBLIC DATETIME (long);

l In initialization, the year, month, and day of the designated. Public DateTime (int, int, int);

l Initialize to specify the designated year, month, and day of Calendar. Public DateTime (int, int, int, calendar);

l Initialize the year, month, day, hour, minute, and seconds. Public DateTime (int, int, int, int, int, int);

l Initialize the designated year, month, day, hours, minutes, and seconds of the designated Calendar. Public DateTime (int, int, int, int, int, int, calendar);

l Initialize the year, month, day, hour, minute, second and milliseconds. Public DateTime (int, int, int, int, int, int, int);

l Initialize the designated year, month, day, hours, minutes, seconds and milliseconds to specify Calendar.

Public DateTime (int, int, int, int, int, int, int, calendar);

Add method

Add the value of the specified Timespan to the value of this instance

Public DateTime Add (Timespan Value);

Value TimeSpan, which contains the interval to be added.

DateTime, its value is the date and time of this example and the time interval indicated by Value

ArgumentOutofRangeException {get the datetime less than minvalue or greater than maxvalue}

parameter

return value

abnormal

This method does not change this DateTime value. But returns a new DateTime, and its value is the result of this operation.

Example

The following description add method. It is calculated that the day of 36 days (ie 864 hours) is the day.

System.datetime Today = system.datetime.now;

System.TimeSpan duration = new system.timespan (36, 0, 0, 0);

System.datetime answer = Today.Add (duration);

AddDays method

Add the specified number of days to the value of this instance

Public DateTime AddDays (Double Value);

The number of days consisting of integers and fractional parts. Value parameters can be negative or positive

Its value is the date and time of this example and the days of the days represented by Value and the arrreging of the argumentoutofrangeexception {get the datetime less than MinValue or greater than maxValue}

parameter

return value

abnormal

Value's fractional part is a fractional part of the day. For example, 4.5 is equivalent to 4 days 12 hours

AddHours Method

Add the specified hour number to the value of this instance

Public DateTime AddHours (double value);

The number of hours consisting of integers and decimal parts. Value parameters can be negative or positive

DateTime, its value is the date and time of this instance and the hour number indicated by Value and the arrival of the argumentoutofrangeexception {get the datetime less than MinValue or greater than maxValue}

parameter

return value

abnormal

Value's fractional part is a fractional part of the day. For example, 4.5 is equivalent to 4 days 12 hours addMilliseConds method

Add the specified millisecond number to the value of this instance

Public DateTime AddMilliseConds (Double Value);

The number of hours consisting of integers and decimal parts. Value parameters can be negative or positive

DateTime, its value is the date and time of this instance and the number of milliseconds represented by Value and the arrival of the argumentoutofrangeexception {get the datetime less than MinValue or greater than maxValue}

parameter

return value

abnormal

Value's fractional part is a fractional part of the day. For example, 4.5 is equivalent to 4 days 12 hours

Addminutes method

Add the specified number of minutes to the value of this instance

Public DateTime Addminutes (Double Value);

The number of hours consisting of integers and decimal parts. Value parameters can be negative or positive

DateTime, its value is the date and time of this instance and the number of minutes represents the number of minutes represents the number of argumentoutofrangeexception {get the datetime less than MinValue or greater than maxValue}

parameter

return value

abnormal

Value's fractional part is a fractional part of the day. For example, 4.5 is equivalent to 4 days 12 hours

AddMontHS method

Add the specified number of months to the value of this instance

Public DateTime AddMonths (Double Value);

The parameter can be a negative number or a positive number

DateTime, its value is the date and time of this instance and the sum of Months. ArgumentOutofRangeException {Get the datetime is smaller than MinValue or greater than maxvalue. - or - MONTHS is less than -12,000 or greater than 120,000. }

parameter

return value

abnormal

AddSeconds method

Add the specified number of seconds to the value of this instance

Public DateTime AddSeconds (Double Value);

The parameter can be a negative number or a positive number

DateTime, its value is the date and time of this instance and the number of seconds represented by Value and the DateTime gigated by argumentOfrangeException {less than MinValue or greater than maxValue.

parameter

return value

abnormal

AddTicks method

Plus the specified scale number to the value of this instance

Public DateTime AddTicks (Double Value);

Take a scale of 100 nanoseconds. Value parameters can be positive or negative numbers

DateTime, its value is the date and time of this instance and the time of Value and the DateTime you get the arrregationOfficoutofrangeException {less than MinValue or greater than maxValue.

parameter

return value

abnormal

Addyear method

Add the specified number of years to the value of this instance

Public DateTime AddyEars (Double Value);

The number can be a negative number or a positive number

DateTime, its value is the date and time of this instance and the number of days indicated by Value and the argumentoutofrangeexception {get the datetime less than MinValue or greater than maxValue.

parameter

return value

abnormal

COMPARE method

Compare the two instances of DateTime and return to their relative value indication

Public Static Int Compa (

DateTime T1,

DateTime T2

);

T1 first DateTime. T2 second datetime. Represents a symbolic number of the relative value of T1 and T2.

Value type condition

Small than zero T1 less than T2. Zero T1 is equal to T2. More than zero T1 is greater than T2. parameter

return value

DateTime T1 = New DateTime (100);

DateTime T2 = New DateTime (20);

IF (DateTime.Compare (T1, T2)> 0) Console.WriteLine ("T1> T2");

IF (DateTime.Compare (T1, T2) == 0) Console.WriteLine ("T1 == T2");

IF (DateTime.Compare (T1, T2) <0) Console.WriteLine ("T1

Compareto method

Compare this example with the specified object and returns a indication of the relative value of the two

Public Virtual Int Compareto (Object Value);

Objects to be compared, or empty reference (Nothing in Visual Basic)

Indicates the relative value of this instance and value

parameter

return value

abnormal

ArgumentException {Value is not a datetime}

System.Datetime these = new system.datetime (system.datetime.today.Year, 7, 28);

INT COMPAREVALUE;

Try {

CompareValue = THEDAY.Compareto (System.Datetime.today);

Catch (argumentexception) {

System.Console.writeline ("Value Is Not A DateTime);

Return;}

IF (CompareValue <0) {

System.console.writeline ("{0: D} is in the point.", Theday;

Else IF (comparevalue == 0) {

System.console.writeline ("{0: D} is Today!", THEDAY);

Else IF (comparevalue == 1) {

System.console.writeline ("Value Is Null";

// comparevalue> 0 && compareValue! = 1

Else {

System.console.writeline ("{0: D} HAS NOT COME YET.", THEDAY);

Date property

Public DateTime Date {get;} The date is the same as this instance, the time value is set to 12 o'clock at midnight (00:00:00)

DAY attribute

Get the date represented by this instance is the first few days in the month

Public int day {get;}

Date value (between 1 and 31)

Attribute value

System.Datetime moment = new system.datetime (1999, 1, 13, 3, 57, 32, 11);

INT year = moment.year; // year gets 1999.

INT MONTH = MOMENT.MONTH; / / MONTH GETS 1 (January).

INT day = moment.day; // day gets 13.int Hour = moment.Hour; // Hour gets 3.

INT minute = moment.minute; // minute gets 57.

INT Second = moment.second; // second Gets 32.

INT Millisecond = moment.millisecond; // MilliseCond Gets 11.

Dayofweek

The date represented by this instance is the day of the week.

Public dayofweek dayofweek {get;}

A DayOfweek enumeration constant, indicating the day of the day. The range of this attribute is from zero (representing Sunday) to six (indicating Saturday)

Dayofweek enumeration

Designated one day

Public Enum Dayofweek

During the calendar in seven days a week, the Dayofweek enumeration represents a week. The scope of this enumeration is from zero (representing Sunday) to six (representing Saturday). This enumeration is useful when it is a strong type of time for a week a day. For example, the enumeration is the type of datetime.dayofweek property.

Friday said on Friday Monday, Saturday, Saturday, Saturday, Saturday, Saturday

Thursday said that Tuesday, Tuesday, showing Tuesday, Wednesday, said Wednesday.

Dayofyear

The date indicated by this instance is the first few days in the year.

Public int dayofyear {get;}

The first few days in the year (between 1 and 366)

Daysinmonth

Returns the number of days specified in the specified month

Public Static Int Daysinmonth

Int year,

Int Month

);

Specifies the number of days in Year in Year.

For example, if Month is equal to 2 (in February), the return value is 28 or 29, depending on whether Year is a leap year. 1

Anomaly type

ArgumentOfficRangeException {MONTH less than 1 or greater than 12}

Const int July = 7;

Const int feb = 2;

Int daysinjuly = system.datetime.daysinmonth (2001, july); // daysinjuly gets 31.

// daysinfeb gets 28 because the year 1998 Was Not a Leap Year.

Int daysinfeb = system.datetime.daysinmonth (1998, feb);

// daysinfebleap gets 29 because the year 1996 Was a leap year.

INT daysinfebleap = system.datetime.daysinmonth (1996, feb);

Equals

Returns a value indicating whether an instance of DateTime is equal to the specified object.

Public Override Bool Equals (Object); Public Override Bool Equals (Object);

System.datetime Today1 = new system.datetime (system.datetime.today.ticks); system.datetime Today2 = new system.datetime (system.datetime.today.ticks);

System.datetime Tomorrow = new system.datetime (system.datetime.today.addday .ticks);

// Todayequalstoday Gets True.

Bool Todayequalstoday = System.Datetime.equals (Today1, Today2);

// TodayequalsTomorrow Gets False.

Bool TodayequalStomorrow = system.datetime.equals (Today1, Tomorrow);

FromFiletime

Returns a DateTime with the specified operating system file timestamp

Public Static DateTime fromFiletime (long filetime); filetime windows file time

Anomaly type

ArgumentOutofRangeException

Note

Filetime has a 64-bit symbol integer value indicating the timestamp of the Windows file. The timestamp is self-coordinated General Time (UTC) AD (C.E.) Time Since 12:00 on January 1, 1601, the time passed by 100 nanoseconds.

Public System.Timespan Fileage (long filecreationtime) {

System.datetime now = system.datetime.now;

Try {

System.datetime FcreationTime = system.datetime.fromfiletime (filecreationTIME);

System.TimeSpan fileage = now.subtract (fcreationTime);

Return fileage;

}

Catch (argumentoutofrangeexception) {

// FileCreationTime is Not Valid, So Re-Throw the Exception.

throw;}}

FromFiletimeutc

Returns DateTime with the specified operating system file timestamp equivalent, has been adjusted to coordinate generic times (UTC)

Public: Static DateTime fromfiletimeutc (

__INT64 filetime);

Filetime Windows file time

Anomaly type

AargumentOutofrangeExceptionn {Filetime less than 0}

Note

Filetime has a 64-bit symbol integer value indicating the timestamp of the Windows file. The timestamp is self-coordinated General Time (UTC) AD (C.E.) Time Since 12:00 on January 1, 1601, the time passed by 100 nanoseconds. Fromfiletimeutc method returns Filetime, 12:00, 12:00, 1 January 1, 1 January 1

Hour

Get the hour part of the date indicated by this example

Public int hour {get;} 小 number (between 0 and 23)

Isleapyear

Returns whether the designated year is a leap year indication

Public static bool isleApyear

int year);

If Year is a leap year, TRUE is true; otherwise, false

MaxValue

Indicates the possible maximum value of the DateTime. This field is read-only

Public Static Readonly DateTime MaxValue;

The value of this constant is equivalent to December 31, 999, 23:59:59.999999, just before 1 month 1 00:00:00 before 00:00

Millisecond

Get a millisecond part of this instance

Public int millisecond {get;}

Minute

Get a millisecond part of this instance

Public int minute {get;} Zhong (between 0 and 59)

Minvalue

Indicates the possible minimum value of the DateTime. This field is read-only

Public Static Readonly DateTime MinValue;

The value of this constant is equivalent to Jan 201, 00: 00:0000000

Month

Get the month part of this instance

Public int MONTH {GET;} Month (between 1 and 12)

NOW

Get a DateTime, it is the current local date and time on this computer.

Public static datetime now {get;}

Parse

Convert the specified string of the date and time to its equivalent DateTime

Public Static DateTime Parse (String);

Public Static DateTime Parse (String, IFORMATPROVIDER);

Public Static DateTime Parse (String, IFORMATPROVIDER, DATETIMESTYLES);

String strmyDatetime = "

2/16/1992

12:15:12 ";

// mydatetime gets Feburary 16, 1992, 12 Hours, 15 min and 12 sec.

System.datetime mydatetime = system.datetime.parse (strmydatetime);

System.iformprovider format = new system.globalization.cultureInfo ("fr-fr", true);

// REVERSE MONTH AND Day TO CONFORM to A DIFFERENT FORMAT.

String strmyDatetimefrench = "

16/02/1992

12:15:12 ";

// mydatetimefrench Gets Feburary 16, 1992, 12 Hours,

// 15 min and 12 sec.

System.Datetime mydatetimefrench =

System.datetime.parse (StrmyDateTimefrench,

Format,

System.globalization.

DateTimeStyles.nocurrentDatedEfault);

String [] expectedformats = {"g", "g", "f", "f"};

// mydatetimefrench Gets Feburary 16, 1992, 12 Hours,

// 15 min and 12 sec.

mydatetimefrench =

System.Datetime.Parsexact (StrmyDateTimefrench,

EXPECTEDFORMATS,

Format, System.globalization.

DateTimeStyles.AllowWhitespaces;

Parsexact

Convert the specified string of the date and time to its equivalent DATETIME. The format of this string representation must be fully matched with the specified format

Public Static DateTime Parsexact (String, String, IFORMATPROVIDER);

Public Static DateTime Parsexact (String, String, IFORMATPROVIDER, DATETIMESTYLES);

Public Static DateTime Parsexact (String, String [], IFORMATPROVIDER, DATETIMESTYLES

SECOND

Get the second part of the date indicated by this instance

Public int second {get;}

Subtract

Subsequently subtract the specified time or duration from this example

Public Timespan Subtract (DateTime);

Public DateTime Subtract (Timespan);

System.datetime Date1 = New System.Datetime (1996, 6, 3, 22, 15, 0);

System.datetime Date2 = New System.datetime (1996, 12, 6, 13, 2, 0);

System.datetime Date3 = New System.Datetime (1996, 10, 12, 8, 42, 0);

// Diff1 Gets 185 Days, 14 Hours, And 47 minutes.

System.TimeSpan Diff1 = Date2.Subtract (Date1);

// date4 gets 4/9/1996

5:55:00 PM

.

System.datetime Date4 = Date3.Subtract (DIFF1);

// Diff2 Gets 55 Days 4 Hours and 20 minutes.

System.TimeSpan Diff2 = Date2 - Date3;

// date5 gets 4/9/1996

5:55:00 PM

.

System.datetime Date5 = DATE1 - DIFF2;

Ticks

Gets the number of dates and times of this instance

Public long ticks {get;}

Indicates the date and time of this example. This value is between MinValue and MaxValue

The value of this attribute is the number of time indicated by 100 nanoseconds from the time of 100 nanoseconds from 12:00, January 1, 0001.

TimeOfday

Get the time of this instance

Public Timespan TimeOfday {Get;}

TimeSpan, it indicates that the day has been over time since Midnight.

Today

Get the current date

Public static datetime today {get;}

DateTime, it is set to this instance date, the time section is set to 00:

00:00 00:00

Tofiletime

Convert this example to the format using the local operating system file time

Public long towile ();

Anomaly type

ArgumentOfficRangeException {This instance cannot be converted to system file time}

The system file time is a 64-bit non-symbol value indicating the date and time, which is a number that is time-separated from 100 nanoseconds since 12:00 on January 1, 1601.

If an attempt to conversion coordination General Time (UTC), the date before 12:00 on January 1, 1601, will cause an exception.

TOFILETIMEUTC converts the value of this instance to the format of the operating system file time, regardless of the local time zone

Public static datetime today {get;}

DateTime, it is set to this instance date, the time section is set to 00:

00:00 00:00

Anomaly type

ArgumentOutofRangeException {The generated file time will be less than 0}

The file time is a 64-bit sign integer value indicating the timestamp of the Windows file. The timestamp is self-coordinated General Time (UTC) AD (C.E.) Time Since 12:00 on January 1, 1601, the time passed by 100 nanoseconds. The TofileTimeutc method returns the value of this DateTime with respect to 12:00 Midnight on January 1, but will not consider the local time zone adjustment

Tolocaltime

Convert this instance to the format of the operating system file time, regardless of the local time zone

Public static datetime today {get;}

DateTime, it is set to this instance date, the time section is set to 00:

00:00 00:00

Anomaly type

ArgumentOutofRangeException {The generated file time will be less than 0}

The file time is a 64-bit sign integer value indicating the timestamp of the Windows file. The timestamp is self-coordinated General Time (UTC) AD (C.E.) Time Since 12:00 on January 1, 1601, the time passed by 100 nanoseconds. The TofileTimeutc method returns the value of this DateTime with respect to 12:00 Midnight on January 1, but will not consider the local time zone adjustment

Tofiletime

Convert this example to the format using the local operating system file time

Public long towile ();

Anomaly type

ArgumentOfficRangeException {This instance cannot be converted to system file time}

The system file time is a 64-bit non-symbol value indicating the date and time, which is a number that is time-separated from 100 nanoseconds since 12:00 on January 1, 1601.

If an attempt to conversion coordination General Time (UTC), the date before 12:00 on January 1, 1601, will cause an exception.

TolongDatestring

Convert this instance value to its equivalent long-term string representation

Public string tolongdatestring ();

A string, which contains the date with the date value of this instance is the name of the day, the month name, the number date and year in this month.

The value of this instance is formatted using long-term format characters "D". The return value is the same as the value returned by TOSTRING ("D", NULL).

For more information on format characters, format mode, and the output they generate, see Format Overview. For more information on changing format modes related to format characters, see the DateTimeFormatinfo class.

This method uses format information from current area. For more information on current regionality, see the CurrentCulture class. You can use the CultureInfo.dateTimeFormat property to get the current regional DateTimeFormatinfo.

System.Datetime DTIME = New System.Datetime (2001, 5, 16, 3, 2, 15);

// if the current culture is "us-en",

// longdatestring gets "

Wednesday, May 16, 2001

"

String longdatestring = dtime.tolongdateString ();

// if the current culture is "us-en", // longTimeString gets "

3:02:15 AM

"

String longTimeString = DTIME.TOLONGTIMESTRING ();

TolongTimeString

Convert this example to its equivalent long string representation

Public String TolongTimeString ();

A string equivalent to the time value in this instance, which contains the Sunday name of the day, the name of the month and the number of hours, divisions, and seconds.

The value of this instance is formatted using a long-time format character "T". The return value is the same as the value returned by TOSTRING ("T", NULL).

For more information on format characters, format mode, and the output they generate, see Format Overview. For more information on changing format modes related to format characters, see the DateTimeFormatinfo class.

ToshortdateString

Convert this example to its equivalent short date string representation

Public String ToshortdateString ();

Convert this instance value to its equivalent short date string representation.

A string that contains digital months equivalent to this instance, the number of numbers and years in the month.

The value of this instance is formatted using a short date format character "D". The return value is the same as the value returned by TOSTRING ("D", NULL).

ToshostTimeString

Converting the value of this instance to its equivalent short-time string representation

Public String ToshortTimeString ();

A string equivalent to the time value in this instance, which contains the Sunday name of the day, the name of the month and the number of hours, divisions, and seconds.

The value of this instance is formatted using a short time format character "T". The return value is the same as the value returned by TOSTRING ("T", NULL).

TouniversalTime

Converting the current local time to coordinate generic times (UTC)

Public DateTime TouniversalTime ();

Equivalently UTC DateTime in the current local time.

- or - the current local time is too large, it cannot be represented as DateTime, is MaxValue.

- or - the current local time is too small, it is not a DateTime, is minValue.

UTC time is equal to local time minus UTC offset. For more information on the UTC offset, see timezone.getutcoffset.

This method assumes that the current DateTime saves local time values ​​instead of UTC time. Therefore, each time it runs, the current method performs the necessary modifications for DateTime to export UTC times, regardless of whether or not the current datetime is local time. This method always uses local time zones when calculating.

UTCNOW

Get a DateTime that is currently currently localized and time on this computer represented by coordination of common time (UTC)

Public static datetime utcnow {get;}

Get a DateTime that is currently the current local date and time on this computer represented by coordination of generic times (UTC).

Public static datetime utcnow {get;}

Property Value: Its value is the current UTC date and time of DateTime.

Remarks: The resolution of this property depends on the system timer.

SYSTEM

Approximate resolution

Windows NT 3.5 and later

10 milliseconds

WINDOWS 98

55 ms

转载请注明原文地址:https://www.9cbs.com/read-20677.html

New Post(0)