//DateTime转换为时间戳
public long GetTimeSpan(DateTime time)
{
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1,0,0,0,0));
    return (long)(time - startTime).TotalSeconds;
}
//timeSpan转换为DateTime
public DateTime TimeSpanToDateTime(long span)
{
  DateTime time = DateTime.MinValue;
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1,0,0,0,0));
  time=startTime.AddSeconds(span);
  return time;
}

C# 时间戳与DateTime间的互相转换的更多相关文章

  1. Python字符串、时间戳、datetime时间相关转换

    总结的时间转换函数 # datetime时间转为字符串 def Changestr(datetime1): str1 = datetime1.strftime('%Y-%m-%d %H:%M:%S') ...

  2. python中时间戳,datetime 和时间字符串之间得转换

    # datetime时间转为字符串def Changestr(datetime1):    str1 = datetime1.strftime('%Y-%m-%d %H:%M:%S')    retu ...

  3. C# 字符串string类型转换成DateTime类型 或者 string转换成DateTime?(字符串转换成可空日期类型)

    在c#中,string类型转换成DateTime类型是经常用到的,作为基本的知识,这里在此做个小结.一般来说可以使用多种方法进行转换,最常用的就是使用Convert.ToDateTime(string ...

  4. Asp.Net Unix时间戳和DateTime类型转换

    using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System. ...

  5. 完善GDAL与OpenCV间的数据格式转换与影像分块读写

    本博客为原创内容,未经博主允许禁止转载,商用,谢谢. 一.前言 关于GDAL与openCV间的数据格式转换,在我之前的博客中已有简要说明,这里,由于最近工作上经常用到openCV里的函数进行图像处理, ...

  6. JAVA线程间的状态转换

    线程间的状态转换:  1. 新建(new):新创建了一个线程对象. 2. 可运行(runnable):线程对象创建后,其他线程(比如main线程)调用了该对象的start()方法.该状态的线程位于可运 ...

  7. c#之时间戳与DateTime的相互转换

    1. 时间戳转 DateTime static DateTime GetServerNow(ulong serverTime) { DateTime dateTimeStart = TimeZone. ...

  8. Java 整数型的进制间的互相转换

    /** * 整数型, 进制间的互相转换 */ public class IntConversion { public static void main(String[] args) { int num ...

  9. mfc 类型间的强制转换

    一. static_cast运算符 用法:static_cast < type-id > ( expression ) 该运算符把expression 转换为type-id类型,但没有运行 ...

随机推荐

  1. new 运算符干了什么

    为了追本溯源, 我顺便研究了new运算符具体干了什么?发现其实很简单,就干了三件事情. var obj = {}; obj.__proto__ = F.prototype; F.call(obj); ...

  2. iOS - Properties 入门

    iOS中,类的属性property可以有若干个修饰词,对应不同的属性行为. @property (readonly) NSString *readonly; // 只读,不可修改 @property ...

  3. 2个版本并存的python使用新的版本安装django的方法

    2个版本并存的python使用新的版本安装django的方法 默认是使用 pip install django 最新版的django会提示  要求python版本3.4以上,系统默认的版本是2.7.5 ...

  4. PowerDesigner软件的使用

    1. 报错:Could not Initialize JavaVM 的解决方案: powerDesigner不支持x64JDK,ok.安装32位. 仅仅是安装一下,不要做任何配置.......关闭po ...

  5. 33.使用默认的execAndWait拦截器

    转自:https://wenku.baidu.com/view/84fa86ae360cba1aa911da02.html 当我们进行数据库查询等相关的操作时,如果服务器负荷过重可能不能及时把数据查询 ...

  6. C#抽象类与接口的区别【转】

    一.抽象类:      抽象类是特殊的类,只是不能被实例化(可以用派生类实例化基类对象):除此以外,具有类的其他特性:重要的是抽象类可以包括抽象方法(当然它可以有普通方法),这是普通类所不能的.抽象方 ...

  7. centos7 配置dns服务器

    yum install bind ----------------------------------------------------------------------------------- ...

  8. 牛X的FieldBlur

    [牛X的FieldBlur] Use Field Blur to build a gradient of blurs, by defining multiple blur points with di ...

  9. 【bzoj1597】[Usaco2008 Mar]土地购买

    1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3739  Solved: 1376[Submit] ...

  10. 转)GPL、BSD、MIT、Mozilla、Apache和LGPL的区别

    开源许可证GPL.BSD.MIT.Mozilla.Apache和LGPL的区别 以下是上述协议的简单介绍: BSD开源协议 BSD开源协议是一个给于使用者很大自由的协议.基本上使用者可以”为所欲为”, ...