C#.net Get time Month date Time minutes format

Source: Internet
Author: User
Tags datetime
c#.net Get time Month date Time minutes formatGet Date + Time
DateTime.Now.ToString (); 2008-9-4 20:02:10
DateTime.Now.ToLocalTime ().        ToString (); 2008-9-4 20:12:12

Get Date
DateTime.Now.ToLongDateString ().    ToString (); September 4, 2008
DateTime.Now.ToShortDateString ().    ToString (); 2008-9-4
DateTime.Now.ToString ("Yyyy-mm-dd"); 2008-09-04
DateTime.Now.Date.ToString (); 2008-9-4 0:00:00
Get time
DateTime.Now.ToLongTimeString ().   ToString (); 20:16:16
DateTime.Now.ToShortTimeString ().   ToString (); 20:16
DateTime.Now.ToString ("Hh:mm:ss"); 08:05:57
DateTime.Now.TimeOfDay.ToString (); 20:33:50.7187500

Other
Datetime.tofiletime ().       ToString (); 128650040212500000
DATETIME.NOW.TOFILETIMEUTC ().   ToString (); 128650040772968750
DateTime.Now.ToOADate ().       ToString (); 39695.8461709606
DateTime.Now.ToUniversalTime ().   ToString (); 2008-9-4 12:19:14

DateTime.Now.Year.ToString (); Get year//2008
DateTime.Now.Month.ToString (); Get Month//9
DateTime.Now.DayOfWeek.ToString (); Get Week//Thursday
DateTime.Now.DayOfYear.ToString (); Get days//248
DateTime.Now.Hour.ToString (); Get hours//20
DateTime.Now.Minute.ToString (); Get minutes//31
DateTime.Now.Second.ToString (); Get seconds//45

N is a number, you can count integers, you can do decimal
Dt. Addyears (n).   ToString (); Time Plus n years
Dt. AddDays (n).   ToString (); Plus n days
Dt. AddHours (n).   ToString (); Plus n Hours
Dt. Addmonths (n).   ToString (); Add N a month
Dt. AddSeconds (n).   ToString (); Plus n seconds

Dt. AddMinutes (n).   ToString (); Plus n points

. NET Date format conversions

DateTime dt = DateTime.Now;
Dt. ToString ();//2005-11-5 13:21:25
Dt. Tofiletime (). ToString (); 127756416859912816
Dt. TOFILETIMEUTC ().                    ToString (); 127756704859912816
Dt. ToLocalTime ().                    ToString (); 2005-11-5 21:21:25
Dt. Tolongdatestring ().                    ToString (); November 5, 2005
Dt. Tolongtimestring ().                    ToString (); 13:21:25
Dt. ToOADate ().                    ToString (); 38661.5565508218
Dt. ToShortDateString ().                    ToString (); 2005-11-5
Dt. Toshorttimestring ().                    ToString (); 13:21
Dt. ToUniversalTime (). ToString (); 2005-11-5 5:21:25
Dt.                    Year.tostring (); 2005
Dt.                    Date.tostring (); 2005-11-5 0:00:00
Dt.                              Dayofweek.tostring (); Saturday
Dt. Dayofyear.tostring ();//309
Dt.                    Hour.tostring (); 13
Dt.Millisecond.ToString ();//441
Dt.                    Minute.tostring (); 30
Dt.                    Month.tostring (); 11
Dt. Second.tostring ();//28
Dt.                    Ticks.tostring (); 632667942284412864
Dt.                    Timeofday.tostring (); 13:30:28.4412864
Dt.                    ToString (); 2005-11-5 13:47:04
Dt. Addyears (1).                    ToString (); 2006-11-5 13:47:04
Dt. AddDays (1.1).                    ToString (); 2005-11-6 16:11:04
Dt. AddHours (1.1).                    ToString (); 2005-11-5 14:53:04
Dt. Addmilliseconds (1.1).                    ToString (); 2005-11-5 13:47:04
Dt. Addmonths (1).                    ToString (); 2005-12-5 13:47:04
Dt. AddSeconds (1.1).                    ToString (); 2005-11-5 13:47:05
Dt. AddMinutes (1.1).                    ToString (); 2005-11-5 13:48:10
Dt. Addticks (1000).                    ToString (); 2005-11-5 13:47:04
Dt.compareto (DT).                    ToString (); 0
Dt. ADD (?).                    ToString (); Question mark is a time period
Dt. Equals ("2005-11-6 16:11:04").                    ToString (); False
Dt. Equals (DT).                    ToString (); True
Dt. GetHashCode ().                    ToString (); 1474088234
Dt. GetType ().                    ToString (); System.DateTime
Dt. GetTypeCode ().                    ToString (); Datetime

Dt. Getdatetimeformats (' s ') [0].                    ToString (); 2005-11-05t14:06:25
Dt. Getdatetimeformats (' t ') [0].                    ToString (); 14:06
Dt. Getdatetimeformats (' y ') [0].                    ToString (); November 2005
Dt. Getdatetimeformats (' D ') [0].                    ToString (); November 5, 2005
Dt. Getdatetimeformats (' D ') [1].                    ToString (); 2005 11 05
Dt. Getdatetimeformats (' D ') [2].                    ToString (); Saturday 2005 11 05
Dt. Getdatetimeformats (' D ') [3].                    ToString (); Saturday November 5, 2005
Dt. Getdatetimeformats (' M ') [0].                    ToString (); November 5
Dt. Getdatetimeformats (' f ') [0].                    ToString (); November 5, 2005 14:06
Dt. Getdatetimeformats (' g ') [0].                    ToString (); 2005-11-5 14:06
Dt. Getdatetimeformats (' R ') [0].                    ToString (); Sat, Nov, 14:06:25 GMT

String.                    Format ("{0:d}", DT); 2005-11-5
String.                    Format ("{0:d}", DT); November 5, 2005
String.                    Format ("{0:f}", DT); November 5, 2005 14:23
String.                    Format ("{0:f}", DT); November 5, 2005 14:23:23
String.                    Format ("{0:g}", DT); 2005-11-5 14:23
String.                    Format ("{0:g}", DT); 2005-11-5 14:23:23
String.                    Format ("{0:m}", DT); November 5
String. Format ("{0:r}", DT);//sat, Nov-14:23:23 GMT
String.                    Format ("{0:s}", DT); 2005-11-05t14:23:23
String. Format ("{0:t}", DT);//14:23
String.                    Format ("{0:t}", DT); 14:23:23
String.                    Format ("{0:u}", DT); 2005-11-05 14:23:23z
String.                    Format ("{0:u}", DT); November 5, 2005 6:23:23
String.                    Format ("{0:y}", DT); November 2005
String.                    Format ("{0}", DT); 2005-11-5 14:23:23
String. Format ("{0:yyyymmddhhmmssffff}", DT);


Calculates the number of days difference between 2 dates
-----------------------------------------------
DateTime dt1 = Convert.datetime ("2007-8-1");
DateTime DT2 = Convert.datetime ("2007-8-15");
TimeSpan span = dt2. Subtract (DT1);
int Daydiff = span. Days + 1;

Calculate the number of days of a month in a year
-----------------------------------------------
int days = Datetime.daysinmonth (2007, 8);
days = 31;

Add a day to the date and reduce the day
-----------------------------------------------
DateTime DT =datetime.now;
Dt. AddDays (1); Add a day
Dt. AddDays (-1);//Reduce one day
Other year methods are similar ...

Convert date functions in Oracle SQL
-----------------------------------------------
To_date ("2007-6-6", ' Yyyy-mm-dd ");
To_date ("2007/6/6", ' Yyyy/mm/dd ");


As the next set of data, how to find the table contains September records:
Cggc_stratdate cggc_enddate
=========================================
2007-8-4 2007-9-5
2007-9-5 2007-9-20
2007-9-22 2007-10-5

SELECT * from TABLE
(To_date (' 2007/9/1 ', ' yyyy/mm/dd ') BETWEEN cggc_stratdate
and Cggc_enddate OR cggc_stratdate >=to_date (' 2007/9/1 ', ' yyyy/mm/dd ')
and Cggc_enddate<=to_date (' 2007/9/30 ', ' yyyy/mm/dd ') "
OR to_date (' 2007/9/30 ', ' yyyy/mm/dd ') BETWEEN cggc_stratdate
and cggc_enddate) Order by Cggc_stratdate ASC

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.