How to get the current date and time in C #
This article introduces how to get the current date and time in c#, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.
DateTime summary
We can get the current time by using the class DataTime. We can get different times by calling various methods in the class: for example, date (2008-09-04), time (12:12:12), date + time (2008-09-04 12:11:10), and so on.
/ / get date + time
DateTime.Now.ToString (); / / 2008-9-4 20:02:10
DateTime.Now.ToLocalTime () .ToString (); / / 2008-9-4 20:12:12
/ / acquisition 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
/ / acquire 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 3315 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 the day / / 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 or decimals.
Dt.AddYears (n) .ToString (); / / time plus n years
Dt.AddDays (n) .ToString (); / / plus n days
Dt.AddHours (n) .ToString (); / / add n hours
Dt.AddMonths (n) .ToString (); / / plus n months
Dt.AddSeconds (n) .ToString (); / / add n seconds
Dt.AddMinutes (n) .ToString (); / / add n
On how to get the current date and time in c # to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.