本文整理汇总了C#中System.DateTime.AddTicks方法的典型用法代码示例。如果您正苦于以下问题:C# System.DateTime.AddTicks方法的具体用法?C# System.DateTime.AddTicks怎么用?C# System.DateTime.AddTicks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTime
的用法示例。
在下文中一共展示了System.DateTime.AddTicks方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToDateTime
// Converts a given datetime in DMTF format to System.DateTime object.
static System.DateTime ToDateTime(string dmtfDate)
{
System.DateTime initializer = System.DateTime.MinValue;
int year = initializer.Year;
int month = initializer.Month;
int day = initializer.Day;
int hour = initializer.Hour;
int minute = initializer.Minute;
int second = initializer.Second;
long ticks = 0;
string dmtf = dmtfDate;
System.DateTime datetime = System.DateTime.MinValue;
string tempString = string.Empty;
if ((dmtf == null))
{
throw new System.ArgumentOutOfRangeException();
}
if ((dmtf.Length == 0))
{
throw new System.ArgumentOutOfRangeException();
}
if ((dmtf.Length != 25))
{
throw new System.ArgumentOutOfRangeException();
}
try
{
tempString = dmtf.Substring(0, 4);
if (("****" != tempString))
{
year = int.Parse(tempString);
}
tempString = dmtf.Substring(4, 2);
if (("**" != tempString))
{
month = int.Parse(tempString);
}
tempString = dmtf.Substring(6, 2);
if (("**" != tempString))
{
day = int.Parse(tempString);
}
tempString = dmtf.Substring(8, 2);
if (("**" != tempString))
{
hour = int.Parse(tempString);
}
tempString = dmtf.Substring(10, 2);
if (("**" != tempString))
{
minute = int.Parse(tempString);
}
tempString = dmtf.Substring(12, 2);
if (("**" != tempString))
{
second = int.Parse(tempString);
}
tempString = dmtf.Substring(15, 6);
if (("******" != tempString))
{
ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000))));
}
if (((((((((year < 0)
|| (month < 0))
|| (day < 0))
|| (hour < 0))
|| (minute < 0))
|| (minute < 0))
|| (second < 0))
|| (ticks < 0)))
{
throw new System.ArgumentOutOfRangeException();
}
}
catch (System.Exception e)
{
throw new System.ArgumentOutOfRangeException(null, e.Message);
}
datetime = new System.DateTime(year, month, day, hour, minute, second, 0);
datetime = datetime.AddTicks(ticks);
System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime);
int UTCOffset = 0;
int OffsetToBeAdjusted = 0;
long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute)));
tempString = dmtf.Substring(22, 3);
if ((tempString != "******"))
{
tempString = dmtf.Substring(21, 4);
try
{
UTCOffset = int.Parse(tempString);
}
catch (System.Exception e)
{
throw new System.ArgumentOutOfRangeException(null, e.Message);
}
OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset)));
datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted)));
}
//.........这里部分代码省略.........