1970年1月1日(00:00:00 GMT)Unix 时间戳(Unix Timestamp)对时间转换

将Long类型转换为DateTime类型,时间戳为毫秒的转换

        /// <summary>
/// 将Long类型转换为DateTime类型
/// </summary>
/// <param name="d">long</param>
/// <returns></returns>
public static DateTime ConvertLongDateTime(long ticks)
{
DateTime dtBase = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
DateTime convertTime = dtBase.Add(new TimeSpan(ticks * TimeSpan.TicksPerMillisecond)).ToLocalTime();
return convertTime;
}

时间戳以秒为单位的转换

        /// <summary>
/// 将Long类型转换为DateTime类型
/// </summary>
/// <param name="d">long</param>
/// <returns></returns>
public static DateTime ConvertLongDateTime(long ticks)
{
DateTime dtBase = new DateTime(, , , , , , DateTimeKind.Utc);
DateTime convertTime = dtBase.Add(new TimeSpan(ticks * TimeSpan.TicksPerSecond)).ToLocalTime();
return convertTime;
}

  将DateTime类型转换为long类型

        /// <summary>
/// 将DateTime类型转换为long类型
/// </summary>
/// <param name="dt">时间</param>
/// <returns></returns>
public static long ConvertDataTimeLong(DateTime dt)
{
DateTime dtBase = new DateTime(, , , , , , DateTimeKind.Utc);
TimeSpan toNow = dt.ToUniversalTime().Subtract(dtBase);
long timeStamp = toNow.Ticks/;
return timeStamp;
}

用C#转出的结果如果是new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc),因为精度问题需要/10000 获取以毫秒精度的时间戳 /10000000获取以秒为精度的时间戳

从1970年1月1日00:00:00 GMT以来此时间对象表示的毫秒数转化为Datetime的更多相关文章

  1. Java 获取各时区时间,获取当前时间到格林威治时间1970年01月01日00时00分00秒的秒数

    格林威治时间即UTC/GMT时间,1970年01月01日00时00分00秒(即UTC+8的北京时间1970年01月01日08时00分00秒)计算代码如下: /** * 获取指定时间到格林威治时间的秒数 ...

  2. 1970年1月1日(00:00:00 GMT)Unix 时间戳(Unix Timestamp)

    转载自(http://jm.ncxyol.com/post-88.html) 今天在看Python   API时,看到time模块: The epoch is the point where the ...

  3. java为啥计算时间从1970年1月1日开始

    http://www.myexception.cn/program/1494616.html ————————————————————————————————————————————————————— ...

  4. [网站公告]3月10日23:00-4:00阿里云SLB升级,会有4-8次连接闪断

    大家好,阿里云将于3月10日23:00-4:00对负载均衡服务(SLB)做升级操作,升级期间SLB网络连接会有约4-8次闪断.由此给您带来麻烦,敬请谅解! 阿里云SLB升级公告内容如下: 尊敬的用户: ...

  5. 格林治时间,也就是返回从 UTC 1970 年 1 月 1 日午夜开始经过的毫秒数。

    格林治时间,也就是返回从 UTC 1970 年 1 月 1 日午夜开始经过的毫秒数. (* Delphi获取13位格林治时间实现方法, 与java中的java.lang.System.currentT ...

  6. DedeCMS文章编辑不更新时间1970年1月1日

    在修改文章或者后期优化的时候,织梦dedecms5.7版本存在一个问题,修改文章的同时也修改了文章的发布时间,这个功能可能有些人比较需要,但同时也有些站长朋友又不需要,因为我们编辑某个文章的时候,发现 ...

  7. [云上天气预报-有时有闪电]2月3日23:00-4:00阿里云SLB升级期间网络会闪断

    大家好,2月3日23:00-2月4日4:00,阿里云将对SLB(负载均衡)进行升级,在升级期间,SLB会有约4-8次的网络闪断.由此给您带来麻烦,望谅解! 阿里云官方公告内容如下: 尊敬的用户: 您好 ...

  8. ASP.NET的gridview设置数据格式(DataFormatString="{}") 2011年04月08日 16:26:00 阅读数:5318 标签: asp.net datagrid integer asp date strin

    select convert(numeric(8,2),round(UnTaxAmount,2))as UnTaxAmount from View_SaleVoiceselect   cast(UnT ...

  9. [网站公告]1月10日1:00-7:00阿里云RDS维护会造成30秒闪断

    大家好! 阿里云将于1月10号1:00-7:00(今天夜里)对杭州机房部分RDS实例所在的物理主机做维护操作,维护期间部分RDS实例会有1-2次闪断,每次闪断时间在30秒以内. 我们使用的RDS实例将 ...

随机推荐

  1. 为什么静态成员、静态方法中不能用this和super关键字

    1.      在静态方法中是不能使用this预定义对象引用的,即使其后边所操作的也是静态成员也不行. 因为this代表的是调用这个函数的对象的引用,而静态方法是属于类的,不属于对象,静态方法成功加载 ...

  2. 比较compareTo与equals及==的区别

    1.compareTo: 附上:源码: public int compareTo(String anotherString) {         int len1 = value.length;   ...

  3. Codeforces Round #372 (Div. 2) A B C 水 暴力/模拟 构造

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. html5表单新特性

    type=range 值区域范围 默认值(0-100) type=data  选择日期 type=color value='初始值' 颜色选择器控件 type=search 搜索框效果 type=im ...

  5. 转 用 AXIOM 促进 XML 处理

    转自:http://www.ibm.com/developerworks/cn/xml/x-axiom/ AXIOM 还不是另一种对象模型.它有着明确的设计目标:大幅提升 Apache 下一代 SOA ...

  6. 按Right-BICEP的测试用例

    测试方法:Right-BICEP 测试计划 1.Right-结果是否正确? 2.B-是否所有的边界条件都是正确的? 3.P-是否满足性能要求? 4.结果是否有符合要求的20道题目? 5.所得到的最大数 ...

  7. 1-4-2 Windows数据类型与重要数据结构

    主要内容:介绍Windows数据类型与重要数据结构 1.数据类型 在Windows系统中定义了Windows应用程序中包含种类繁多的数据类型, 部分如下: WORD 16位无符号整数 typedef ...

  8. 学习Logistic Regression的笔记与理解(转)

    学习Logistic Regression的笔记与理解 1.首先从结果往前来看下how logistic regression make predictions. 设我们某个测试数据为X(x0,x1, ...

  9. 套接字I/O模型-select

    共有6种类型套接字I/O模型.blocking(阻塞),select(选择),WSAAsyncSelect(异步选择),WSAEventSelect(事件选择),overlapped(重叠),comp ...

  10. 007. 自定义ListBox的item的宽高, 字体居中

    /// <summary> /// 自定义ListBox的item的宽高, 字体居中 /// </summary> /// <param name="sende ...