(go) Use the Datatime class to get the current time

Source: Internet
Author: User

1We can get the current time by using the Datatime class. By invoking various methods in the class we can get different times: for example: Date ( -- the-Geneva), Time ( A: A: A), Date + time ( -- the-Geneva  A: One:Ten) and so on. 2 3 //Get date + time4DateTime.Now.ToString ();//2008-9-4 20:02:105DateTime.Now.ToLocalTime (). ToString ();//2008-9-4 20:12:126 7 //Get Date8DateTime.Now.ToLongDateString (). ToString ();//September 4, 20089DateTime.Now.ToShortDateString (). ToString ();//2008-9-4TenDateTime.Now.ToString ("YYYY-MM-DD");//2008-09-04 OneDateTime.Now.Date.ToString ();//2008-9-4 0:00:00 A  - //Get Time -DateTime.Now.ToLongTimeString (). ToString ();//20:16:16 theDateTime.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 ADateTime.Now.ToOADate (). ToString ();//39695.8461709606 atDateTime.Now.ToUniversalTime (). ToString ();//2008-9-4 12:19:14 -  -DateTime.Now.Year.ToString (); Get year// - -DateTime.Now.Month.ToString (); Get month//9 -DateTime.Now.DayOfWeek.ToString (); Get Week//Thursday -DateTime.Now.DayOfYear.ToString (); Get the day of the week//248 inDateTime.Now.Hour.ToString (); Get hours// - -DateTime.Now.Minute.ToString (); Get minutes// to toDateTime.Now.Second.ToString (); Gets the number of seconds// $ +  - //N is a number, can be a number of integers, can also matter a decimal theDt. AddYears (n). ToString ();//time plus n years *Dt. AddDays (n). ToString ();//Plus n days $Dt. AddHours (n). ToString ();//Add n hoursPanax NotoginsengDt. AddMonths (n). ToString ();//Add n months -Dt. AddSeconds (n). ToString ();//Plus n seconds theDt. AddMinutes (n). ToString ();//Add n points +  A  the SQL statements use time and date functions +  -  $ getdate (): Gets the current time of the system $DATEADD (datepart,number,date): Calculates a new time value after a time based on a time, such as: DateAdd (yy, -, GETDATE ()) -DateDiff (datepart,startdate,enddate): Calculates the difference of two time, such as: DateDiff (Yy,getdate (),'2008-08-08') - Dataname (datepart,date): Gets the value of a different part of time, the return value is a string the datepart (datepart,date): Similar to Datename, except that the return value is integer type - Day: Gets the number of days of the specified timeWuyi Month (date): Gets the month of the specified time the year (date): Gets the years of the specified time -  Wu SelectYear (GETDATE ()): Current Years

(go) Use the Datatime class to get the current time

Related Article

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.