Time functions in C#

WBOY
Release: 2023-09-15 21:37:02
forward
716 people have browsed it

C# 中的时间函数

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 -

##1 23456
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

Let us understand a Time function i.e. AddMilliseconds(Double) which adds the specified number of milliseconds to the value of this instance .

Example

Real-time demonstration

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);

   }
}
Copy after login

Output

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)
Copy after login

The above is the detailed content of Time functions in C#. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!