C # Date function use Daquan

Source: Internet
Author: User

1 DateTime dt = DateTime.Now; 2 3 dt. ToString ();//2005-11-5 13:21:25 4 5 dt. Tofiletime (). ToString ();//127756416859912816 6 7 dt. TOFILETIMEUTC (). ToString ();//127756704859912816 8 9 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-Notoginseng 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 ();//The question mark is a period of time. 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. Getdatetimeformats (' t ') [0]. ToString ();//14:06. Getdatetimeformats (' y ') [0]. ToString ();//November 2005 84 85Dt. Getdatetimeformats (' D ') [0]. ToString ();//November 5, 2005, dt. Getdatetimeformats (' D ') [1]. ToString ();//2005. Dt. Getdatetimeformats (' D ') [2]. ToString ()///week 62,005, dt. Getdatetimeformats (' D ') [3]. ToString ();//Saturday November 5, 2005. Getdatetimeformats (' M ') [0]. ToString ();//November 5 94 dt. Getdatetimeformats (' f ') [0]. ToString ();//November 5, 2005 14:06, dt. Getdatetimeformats (' g ') [0]. ToString ();//2005-11-5 14:06 98. Dt. Getdatetimeformats (' R ') [0]. ToString ();//sat, 2005 14:06:25 GMT100 101 string. Format ("{0:d}", DT);//2005-11-5102 103 string. Format ("{0:d}", dt);//November 5, 2005 104 string. Format ("{0:f}", dt);//November 5, 2005 14:23106 107 string. Format ("{0:f}", dt);//November 5, 2005 14:23:23108 109 string. Format ("{0:g}", DT);//2005-11-5 14:23110 111 string. Format ("{0:g}", DT);//2005-11-5 14:23:23112 113 String. Format ("{0:m}", dt);//November 5. Format ("{0:r}", DT);//sat, 2005 14:23:23 GMT116 117 string. Format ("{0:s}", DT);//2005-11-05t14:23:23118 119 string. Format ("{0:t} ", DT);//14:23120 121 string. Format ("{0:t}", DT);//14:23:23122 123 string. Format ("{0:u}", DT);//2005-11-05 14:23:23z124 string. Format ("{0:u}", dt);//November 5, 2005 6:23:23126 127 string. Format ("{0:y}", dt);//November 2005 129 string. Format ("{0}", dt);//2005-11-5 14:23:23 131 string. Format ("{0:yyyymmddhhmmssffff}", DT); 132 133 134 135 Calculates the difference in days between 2 dates 136 137--------------------------------------------    ---138 139 DateTime dt1 = Convert.datetime ("2007-8-1");   141 DateTime DT2 = Convert.datetime ("2007-8-15"); 142 143 TimeSpan span = DT2.              Subtract (DT1); 144 145 int Daydiff = span.                    Days + 1; 146 147 calculates the number of days in a certain year 148 149-----------------------------------------------151 int day = Datetime.daysinmonth (2007,       8);                                      153 days = 31; 154 155 Add day to date, reduce day 156 157-----------------------------------------------158 159 DateTime DT =datetime.now;160 161 dt. AddDays (1); Add one day 162 163 dt. AddDays (-1);//Reduce Day 164 165 Other years method similar to 166 167 Oracle SQL convert Date function 168 169-----------------------------------------------171 to_date ("2007-6-6", ' Yyyy-mm-dd ' ); 172 173 to_date ("2007/6/6", "Yyyy/mm/dd"); 174 175 176 177 The following set of data, how to find the table contains September records: 178 179 cggc_stratdate cggc_enddate180 181 =========================================182 183 2007-8-4 2007-9-5184 185 2007-9-5 2007-9-20186 187 2007-9-22 2007-  10-5188 189 SELECT * from TABLE190 191 (to_date (' 2007/9/1 ', ' yyyy/mm/dd ') between cggc_stratdate192 193 and Cggc_enddate OR Cggc_stratdate >=to_date (' 2007/9/1 ', ' yyyy/mm/dd ') 194 195 and Cggc_enddate<=to_date (' 2007/9/30 ', ' yyyy/mm/dd ') "196 197 OR to_date (' 2007/9/30 ', ' yyyy/mm/dd ') between cggc_stratdate198 199 and Cggc_enddate) ORDER by Cggc_stratdate ASC

C # Date function use Daquan

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.