DateTime,. NETDateTime in. NET

Source: Internet
Author: User

DateTime,. NETDateTime in. NET
DateTime Introduction

DateTime is a time type in. NET. You can use DateTime to obtain the current system time.
DateTime is a struct in. NET, not a class.
 

As shown in, this icon represents the struct in.

Common methods and members of DateTime
1. Now
Obtain the current system time. Format:

2. Today
Obtain the current today date. Format:

3. mm/sec
The following objects must be passed through
DateTime. Now (or DateTime. Today.
Year get Year Hour get Hour
Month get Month Minute get Minute
Day (s)

// Take Year as an example: DataTime. Now. Year

4. DayOfWeek, DayOfYear
Returns the day of the week.

And obtain the day number of the year from the current date.

5. TryParse ()
Determines whether it is a time type. An out parameter can output a DateTime object.

6. AddDays (), AddHours ()

Returns a DateTime value based on the current time plus a few days.
Returns a DateTime value after several hours based on the current date.
7. Subtract (DateTime. Now)

Returns a TimeSpan when comparing the time difference between two time ranges.

Date and Time Format character ToString ()
Predefined Mode
DateTime date = DateTime. Now;
Date. ToString (Format)
ParametersFormatDetailed format usage
Format character Association attributes/Description
D ShortDatePattern
D LongDatePattern
F complete date and time (long date and short time)
F FullDateTimePattern (long date and long time)
G regular (short date and short time)
G regular (short date and long time)
M, M MonthDayPattern
R, R RFC1123Pattern
S uses SortableDateTimePattern of the local time (based on ISO 8601)
T ShortTimePattern
T LongTimePattern
U UniversalSortableDateTimePattern is used to display the format of common time
U uses the complete date and time of the general time (long date and long time)

Y, Y YearMonthPattern

Custom Mode
D. A single-digit date has no leading zero.
A day in dd month. A single-digit date has a leading zero.
The abbreviation of a day in ddd Week, which is defined in AbbreviatedDayNames.
The full name of the Day of the dddd Week, which is defined in DayNames.
M month number. One-digit month does not have a leading zero.
MM Month number. A single-digit month has a leading zero.
The abbreviated name of the MMM month, which is defined in AbbreviatedMonthNames.
The full name of the MMMM month, which is defined in MonthNames.
Y does not contain the year of the epoch. If the year that does not contain the epoch is less than 10, the year that does not have the leading zero is displayed.
Yy does not contain the year of the epoch. If the year that does not contain the epoch is less than 10, the year with the leading zero is displayed.
Yyyy includes the four-digit year of the epoch.
Gg period or epoch. This mode is ignored if the date to be formatted does not have an associated period or epoch string.
H 12-Hour. One-digit hours do not have a leading zero.
The hour in hh 12-hour format. The number of hours in a single digit has a leading zero.
H In 24-hour format. One-digit hours do not have a leading zero.
The hour in the 24-hour format. The number of hours in a single digit has a leading zero.
M minutes. The number of minutes in a single digit does not start with zero.
Mm minutes. The number of minutes in a single digit has a leading zero.
S seconds. The number of seconds in a single digit does not have a leading zero.
Ss seconds. The number of seconds in a single digit has a leading zero.

 

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.