/// <summary>
/// 将c# DateTime时间格式转换为Unix时间戳格式
/// </summary>
/// <param name="time">时间</param>
/// <returns>long</returns>
public static long ConvertDateTimeToInt(System.DateTime time)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
long t = (time.Ticks - startTime.Ticks) / 10000; //除10000调整为13位
return t;
}
/// <summary>
/// 时间戳转为C#格式时间 timeStamp=146471041000
/// </summary>
/// <param name=”timeStamp”></param>
/// <returns></returns>
private DateTime ConvertStringToDateTime(string timeStamp)
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
long lTime = long.Parse(timeStamp + "0000");
TimeSpan toNow = new TimeSpan(lTime);
return dtStart.Add(toNow);
}

  注:这个日期(1970-1-1),现在计算机和一些电子设备时间的计算和显示是以距历元(即格林威治标准时间 1970 年 1 月 1 日的 00:00:00.000,格里高利历)的偏移量为标准的,有人就戏称英国的格林威治天文台是“时间开始的地方”。

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

  1. scala时间和时间戳互转

    时间转换为时间戳: import java.text.SimpleDateFormat object test { def main(args: Array[String]): Unit = { va ...

  2. C# 时间与时间戳互转 13位

    /// <summary> /// 将c# DateTime时间格式转换为Unix时间戳格式 /// </summary> /// <param name="t ...

  3. C# 时间与时间戳互转 13位|13位時間戳与日期换转

    这里直接上代码 懂C# 的程序猿 一看便知道如何使用的... /// <summary> /// 将Unix时间戳转换为DateTime类型时间 /// </summary> ...

  4. c#时间与时间戳互转13位

    Unix时间戳(Unix timestamp),或称Unix时间(Unix time).POSIX时间(POSIX time),是一种时间表示方式,定义为从格林威治时间1970年01月01日00时00 ...

  5. Shell日期时间和时间戳的转换

    Gitlab的备份文件是以时间戳显示的,类似:1438624820_gitlab_backup.tar 为了更易于阅读,想把文件名转换成日期格式:2015-08-04_gitlab_backup.ta ...

  6. 用shell将时间字符串与时间戳互转

    date的详细用户可以参考下面的 http://www.cnblogs.com/xd502djj/archive/2010/12/29/1919478.html date 的具体用法可以查看另外一篇博 ...

  7. mysql时间操作(时间差和时间戳和时间字符串的互转)

    mysql时间操作(时间差和时间戳和时间字符串的互转) 两个时间差: MySQL datediff(date1,date2):两个日期相减 date1 - date2,返回天数. select dat ...

  8. Mysql 时间、字符串、时间戳互转

    时间转字符串 select date_format(now(),'%Y-%m-%d'); 时间转时间戳 select UNIX_TIMESTAMP(now()); 时间戳转时间 ) :: 时间戳转字符 ...

  9. C#时间与时间戳格式互相转化

    C#时间格式转换为时间戳(互转) 时间戳定义为从格林威治时间 1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数. using UnityEn ...

随机推荐

  1. Script.NET Perl解释器代码已经在GitHub开源发布

    Script.NET Perl解释器的代码已经提交到GitHub网站.GitHub项目地址: https://github.com/blueantst/Script.NET Perl解释器代码在Src ...

  2. 用Regex类计算一个字符串出现次数是最好方法【转载】

    我的一个朋友问我,怎么在c#或vb.net中,计算一个字符串中查找另一个字符串中出现的次数,他说在网上打了好多方法,我看了一下,有的是用replace的方法去实现,这种方法不是太好,占资源太大了.其实 ...

  3. vbs运行批处理

    dim wshellset wshell=createobject("wscript.shell") wshell.run "cmd /c sc query Spoole ...

  4. linux 查看并终止进程

    1,查看port被那个进程占用 比如: netstat -anp | grep 1160 ps:查看port1169被那个进程占用. 2.查找进程 比如 :ps -ef | grep 'tomcat' ...

  5. [Node.js] Creating JWTs (JSON Web Tokens) in Node

    In this lesson we will look at all of the pieces that combine together to create a JWT (j AWT) or JS ...

  6. 最简便的MySql数据库备份方法

    http://www.kankanews.com/ICkengine/archives/194.shtml 使用MYSQL进行数据库备份,又很正规的数据库备份方法,同其他的数据库服务器有相同的概念,但 ...

  7. eclipse 中修改 M2_REPO的值--转载

    从eclipse中增加了maven2的插件之后,maven默认的本地库的路径是${user}/.m2/repository/下,一般windows用户的操作系统都安装在C盘,所以这个目录 下的jar包 ...

  8. How to add route for IPV6 interface

    Firewall : ifconfig eth1 inet6 add 2000::1/64 ifconfig eth4 inet6 add 5000::1/64 ------------------- ...

  9. Android源码解析--Quick Search in Settings

    欢迎大家加入群里交流:429664282 基于:android-6.0.1_r17 f4b8ad6 Android Settings中存在一个SearchIndexablesProvider,它提供了 ...

  10. 使用Keytool工具生成证书Keystore和证书签名请求文件

    内容概览: keytool的几个常用的命令. 1.创建证书 2.查看证书库 3.导出证书文件 4.导入证书的信息 5.查看证书信息 6.删除密钥库中的条目 7.修改证书条目的口令 ---------- ...