c# datetime.
DateTime.AddTicks()方法 (DateTime.AddTicks() Method)
DateTime.AddTicks() method is used to return a new date-time object that adds ticks value of this instance. This object does not change the original value of date-time but it returns an object with the new value.
DateTime.AddTicks()方法用于返回一个新的日期时间对象,该对象添加此实例的刻度值。 该对象不会更改日期时间的原始值,但会返回具有新值的对象。
Syntax:
句法:
DateTime DateTime.AddTicks(long value);
Parameter(s):
参数:
long value – represents a long value to be added in the DateTime object.
long value –表示要添加到DateTime对象中的long值。
Return value:
返回值:
The return type of this method is DateTime, it returns the new value of DateTime object.
此方法的返回类型为DateTime ,它返回DateTime对象的新值。
Example to demonstrate example of DateTime.AddTicks() method
示例,以演示DateTime.AddTicks()方法的示例
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//Create object of datetime class
DateTime dt1 = new DateTime(2019,1,1,5,0,15);
//Adding 5000 ticks using AddTicks method
DateTime dt2 = dt1.AddTicks(5000);
//Display ticks of dt1
Console.WriteLine("Number of ticks in dt1 : " + dt1.Ticks);
//Display ticks of dt2
Console.WriteLine("Number of ticks in dt2 : " + dt2.Ticks);
Console.WriteLine();
}
}
}
Output
输出量
Number of ticks in dt1 : 636819156150000000
Number of ticks in dt2 : 636819156150005000
In the above program, we took the dt1 object of the DateTime class and then add ticks using AddTicks() method and assign an object with new values into dt2. Then print ticks values using Ticks property of DateTime class.
在上面的程序中,我们获取了DateTime类的dt1对象,然后使用AddTicks()方法添加了滴答声,并将具有新值的对象分配给dt2 。 然后使用DateTime类的Ticks属性打印刻度值。
翻译自: https://www.includehelp.com/dot-net/datetime-addticks.aspx
c# datetime.