DateTime学习整理

来源:互联网 发布:js 数组遍历 foreach 编辑:程序博客网 时间:2024/06/10 12:51

C#中的DateTime

几种常见的时间格式:
- 格林尼治时间:简称GMT时间
- 协调世界时,又称UTC时间
- 本地时间

DateTime结构:

DateTime.UtcNow时间:
MSDN解释:

Gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).
UTC时间,全称协调世界时,是一个标准时间,属于尽量接近格林尼治标准时间的时间之一。我又查了一下格林尼治时间(补地理),据维基百科说格林尼治时间已经不是一个标准时间了,即它代表的时间”并不准”,受地球自转速度会有不稳定的误差,因此UTC时间才是现在的标准时间。

DateTime.Now时间:
根据MSDN的解释:

Gets a DateTime object that is set to the current date and time on this computer, expressed as the local time.

简单说DateTime.Now就是本机,比如当前软件环境北京时间东八区的话,拿到的 时间就是当前的UTC时间+8小时。当修改计算机时区的时候,拿到的DateTime.Now也会有所不同。


关于DateTime的属性:

pulic void Test(){    DateTime date = new DateTime();    long ticks=date.Ticks;//获得该时间的时钟计数    long miniliSecond = date.Ticks/10000;//时钟计数除以10000为该时间的毫秒数}

最后关于C#,Unix时间戳使用的一个地址不错,存档啦:
http://www.cnblogs.com/polk6/p/6024892.html

原创粉丝点击