//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. application/json 和 application/x-www-form-urlencoded的区别

    public static string HttpPost(string url, string body) { //ServicePointManager.ServerCertificateVali ...

  2. 接口自动化(六)--使用QQ邮箱发送邮件

    接口测试执行完发送一个邮件,这里使用QQ邮箱发送,先要拿到QQ邮箱授权码,方法自行百度 # coding=utf-8 import smtplib from email.mime.text impor ...

  3. ADO 缓存更新

    if (ADOQuery1->UpdateStatus() == usUnmodified)   return; ADOQuery1->UpdateBatch(arAll); Update ...

  4. spring data jpa、 hibernate、 jpa 三者之间的关系

    http://www.cnblogs.com/xiaoheike/p/5150553.html JPA规范与ORM框架之间的关系是怎样的呢? JPA规范本质上就是一种ORM规范,注意不是ORM框架-- ...

  5. tensorflow 基本函数(1.tf.split, 2.tf.concat,3.tf.squeeze, 4.tf.less_equal, 5.tf.where, 6.tf.gather, 7.tf.cast, 8.tf.expand_dims, 9.tf.argmax, 10.tf.reshape, 11.tf.stack, 12tf.less, 13.tf.boolean_mask

    1.  tf.split(3, group, input)  # 拆分函数    3 表示的是在第三个维度上, group表示拆分的次数, input 表示输入的值 import tensorflow ...

  6. Redhat 7.2 编译安装PostgreSQL 10

    1.环境说明 CentOS7.2 postgresql10.4 2.下载 postgresql的官方地址 https://www.postgresql.org/ftp/source/ 在下载列表中根据 ...

  7. 迷你MVVM框架 avalonjs 0.97发布

    在本版本中,王之三柱臣全部就位! mmRouter: https://github.com/RubyLouvre/mmRouter mmAnimate: https://github.com/Ruby ...

  8. 迷你MVVM框架 avalonjs 1.3.1发布

    avalon1.3.1发布. interpolate支持注释节点做定界符,avalon.config({interpolate:["<!--","-->&qu ...

  9. open中的mode

    [open中的mode] 当使用O_CREAT标志的open来创建文件时,我们必须使用三个参数格式的open调用.第三个参数mode 是几个标志按位OR后得到的.他们是: S_IRUSR: 读权限,文 ...

  10. [Training Video - 7] [Database connection] Part 1

    try, catch and finally in db connection Forming groovy connection string and obtaining Connection Ob ...