C#.NET 日期操作类
来源:互联网 发布:睡眠记录的软件 编辑:程序博客网 时间:2024/05/18 09:04
代码
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace Pub.Class
{
/// <summary>
/// 日期操作类
/// </summary>
public class Date
{
#region ExactTimeSpan
/// <summary>
/// 精确的时间差
/// </summary>
/// <example>
/// <code>
/// context.items["beginrequesttickcount"]=a.gettickcount();
/// 代码段
/// new TimeSpan(A.GetTickCount()-(long)Context.Items["BeginRequestTickCount"]).TotalMilliseconds
/// </code>
/// </example>
public class ExactTimeSpan {
[DllImport("kernel32.dll")]
static extern bool QueryPerformanceCounter([In, Out] ref long lpPerformanceCount);
[DllImport("kernel32.dll")]
static extern bool QueryPerformanceFrequency([In, Out] ref long lpFrequency);
static long _f = 0;
/// <summary>
/// 来纪录程序开始时的TickCount
/// </summary>
/// <returns>TickCount</returns>
static public long GetTickCount() {
long f = _f;
if (f == 0)
if (QueryPerformanceFrequency(ref f)) _f = f; else _f = -1;
if (f == -1) return Environment.TickCount * 10000;
long c = 0;
QueryPerformanceCounter(ref c);
return (long)(((double)c) * 1000 * 10000 / ((double)f));
}
static long _tc = 0;//GetTickCount()为0时的DateTime.Ticks值
/// <summary>
/// 这个返回的不是真正的精确时间,但时间与时间的差是精确的。
/// GetExactNow与DateTime.Now的偏差比DateTime.Now的精度还要小
/// </summary>
/// <returns>时间与时间差</returns>
static public DateTime GetExactNow() {
if (_tc == 0) {
long tc = GetTickCount();
DateTime dt = DateTime.Now;
_tc = dt.Ticks - tc;
return dt;
}
return new DateTime(_tc + GetTickCount());
}
}
#endregion
}
}
- C#.NET 日期操作类
- 简单日期类操作(c++)
- C#.NET注册表操作类
- C#.NET Server类操作
- C#.NET Js操作类
- C#.net 数据操作--excel 操作类
- asp.net各种日期操作
- C#-日期时间-时间日期操作
- jqm 日期选择-c#.net
- ASP.NET日期操作常用操作代码
- objective-C日期相关操作
- asp.net(C#)常用时间日期处理类
- Asp.net 时间操作基类(短日期,长日期,时间差)
- Asp.net 时间操作基类(短日期,长日期,时间差)
- Asp.net 时间操作基类(短日期,长日期,时间差)
- Asp.net 时间操作基类(短日期,长日期,时间差)
- Asp.net 时间操作基类(短日期,长日期,时间差)
- Asp.net 时间操作基类(支持短日期,长日期,时间差)
- C#.NET Server类操作
- Symbian学习--文件系统
- C#.NET Request相关操作
- C#.NET 缩略图处理类CutImage
- J2EE 之读书笔记
- C#.NET 日期操作类
- Using MFC MBCS/Unicode Conversion Macros
- opener
- Effective C++(1-4)
- 【转】通过usb连线组局域网
- 【软件测试自动化-QTP NOTE 8】 == 描述性编程(Descriptive Programming)-Finial ==
- 海量数据整理
- 斯坦德科技
- 3 进程管理