DateTime has methods and properties for date and time, and how to get the hours or minutes of a day, etc.
Let's just focus on the time function -
Please refer to MSDN (Microsoft Developer Network) for all functions -
Sr.No. | Methods and Properties |
---|---|
AddDays(Double) Returns a new DateTime that adds the specified number of days to this instance's value. | |
AddHours(Double)Returns a new DateTime that will specify The number of hours added to this instance's value. | |
AddMilliseconds(Double)Returns the number of new DateTime milliseconds added to the specified number is the value of this instance. | |
AddMinutes(Double)Returns a new DateTime that will specify The number of minutes added to this instance's value. | |
AddSeconds(Double)Returns a new DateTime that will specify The number of seconds to add to this instance's value.
|
|
AddYears(Int32) Returns a new DateTime, adding the specified Number of years is added to the value |
using System; public class Demo { public static void Main() { string dateFormat = "MM/dd/yyyy hh:mm:ss.fffffff"; DateTime dateCurrent = new DateTime(2018, 7, 23, 13, 0, 0); Console.WriteLine("Original date: {0} ({1:N0} ticks)", dateCurrent.ToString(dateFormat), dateCurrent.Ticks); DateTime dateNew = dateCurrent.AddMilliseconds(1); Console.WriteLine("Next date: {0} ({1:N0} ticks)", dateNew.ToString(dateFormat), dateNew.Ticks); } }
Original date: 07/23/2018 01:00:00.0000000 (636,679,476,000,000,000 ticks) Next date: 07/23/2018 01:00:00.0010000 (636,679,476,000,010,000 ticks)
The above is the detailed content of Time functions in C#. For more information, please follow other related articles on the PHP Chinese website!