We can get the current time by using the Datatime class. We can get different times by invoking various methods in the class: Date (2008-09-04), Time (12:12:12), date + time (2008-09-04 12:11:10), etc.
//Get date + time
DateTime.Now.ToString (); < Span class= "Apple-converted-space" > //2008-9-4 20:02:10
DateTime.Now.ToLocalTime (). ToString (); //2008-9-4 20:12:12
//Gets the 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
//gets the 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 year2008
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
DateTime.Now.Hour.ToString (); Get hours //20
DateTime.Now.Minute.ToString (); Get minutes //31
DateTime.Now.Second.ToString (); gets the number of seconds //
N is a number, can be a number of integers, can also matter a decimal
Dt. AddYears (n). ToString ();//Time plus N year
Dt. AddDays (n). ToString (); //Plus n days
Dt. AddHours (n). ToString (); //Plus n hours
Dt. AddMonths (n). ToString (); //Plus n months
Dt. AddSeconds (n). ToString (); //plus n seconds
Dt. AddMinutes (n). ToString (); //Add n points
SQL statement uses time and date functions
GetDate (): Gets the current time of the system
DateAdd (datepart,number,date): Calculates a new time value after adding a time based on a time, such as: DateAdd (Yy,30,getdate ())
DateDiff (datepart,startdate,enddate): Calculates a difference of two time, such as: DateDiff (Yy,getdate (), ' 2008-08-08 ')
Dataname (datepart , date): Gets the value of the different part of time, the return value is String
DatePart (datepart,date): Similar to Datename, except that the return value is Integer
Day (date): Gets the number of days of the specified time
month (date ): Gets the month of the specified time
year (date): Gets the years of the specified time
Select year (GETDATE ()) : Current Years
C # Gets the current date time