首页 新闻 会员 周边

C#里时间转成毫秒数的效率

0
悬赏园豆:10 [已关闭问题] 关闭于 2012-08-08 18:33

1.

static void Main(string[] args)
{
Console.WriteLine("按回车开始遍历 2,000,000 条记录...");
Console.ReadLine();
int tickCount = Environment.TickCount;
int ret = 0;
for (int i = 0; i < 1000000; i++)
{

  DataTime dt = new DataTime();

  long ticks = dt.Ticks;

  // 和调用DateTimeToTicks(。。)比较

}
tickCount = Environment.TickCount - tickCount;
Console.WriteLine("已完成遍历, 总共消耗时间: {0} 毫秒.", tickCount);
Console.ReadLine();
}

----------------------------------------------------

2.

static void Main(string[] args)
{
Console.WriteLine("按回车开始遍历 2,000,000 条记录...");
Console.ReadLine();
int tickCount = Environment.TickCount;
int ret = 0;
for (int i = 0; i < 1000000; i++)
{

   DataTime dt1 =new DataTime(ticks);

  // 和调用TicksToDateTime(...)比较

}
tickCount = Environment.TickCount - tickCount;
Console.WriteLine("已完成遍历, 总共消耗时间: {0} 毫秒.", tickCount);
Console.ReadLine();
}

-----------------------

 long DateTimeToTicks(int year, int month, int day, int hour, int minute, int second)

  {}

void TicksToDateTime(long ticks, ref int year, ref int month, ref int day, ref int hour, ref int minute, int second)  

{}

 

然后自己模拟一下时间转换成毫秒 和毫秒转时间 测效率

循环几百万次测效率,并且要考虑 闰年 

曹wl的主页 曹wl | 初学一级 | 园豆:169
提问于:2012-08-08 14:47
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册