C#时间戳转换[转发]
http://www.cnblogs.com/qingliuyu/p/3835858.html
以下是C#下的日期与unix时间戳的相互转换:
/// <summary>
/// 日期转换成unix时间戳
/// </summary>
/// <param name="dateTime"></param>
/// <returns></returns>
public static long DateTimeToUnixTimestamp(DateTime dateTime)
{
var start = new DateTime(1970, 1, 1, 0, 0, 0, dateTime.Kind);
return Convert.ToInt64((dateTime - start).TotalSeconds);
} /// <summary>
/// unix时间戳转换成日期
/// </summary>
/// <param name="unixTimeStamp">时间戳(秒)</param>
/// <returns></returns>
public static DateTime UnixTimestampToDateTime(this DateTime target, long timestamp)
{
var start = new DateTime(1970, 1, 1, 0, 0, 0, target.Kind);
return start.AddSeconds(timestamp);
}
/// <summary>
/// unix时间戳转换成日期
/// </summary>
/// <param name="unixTimeStamp">时间戳(秒)</param>
/// <returns></returns>
public static DateTime UnixTimestampToDateTime(long timestamp)
{
var start = new DateTime(1970, 1, 1, 8, 0, 0, DateTimeKind.Unspecified);
return start.AddMilliseconds(timestamp);
}
C#时间戳转换[转发]的更多相关文章
- 【C#】时间戳转换
今天有时间戳转换的需求,网上找了半天才找到相关代码,经测试有效,特作此笔记和大家分享! 1.时间戳转为C#格式时间 /// <summary> /// 时间戳转为C#格式时间 /// &l ...
- 1:时间戳转换成年月日函数,2:url截取参数方法,3:弹窗自定义方法 4:点击按钮加入购物车
最近一直在使用vue.js来构建项目,先分享一下一些简单可复用的函数. 1:时间戳转换Date.prototype.format = function(fmt){ //author: yumeiqia ...
- Unix时间戳转换怎样在Excel批量修改?
最近在操作项目的时候碰到一个Unix时间戳转换的问题."date_time":1393031347这个是什么,你知道吗?如果你对Unix时间戳了解的话一眼就看出来.但我们本着科普的 ...
- piap.excel 微软 时间戳转换mssql sql server文件时间戳转换unix 导入mysql
piap.excel 微软 时间戳转换mssql sql server文件时间戳转换unix 导入mysql 需要不个mssql的sql文件导入mysql.他们的时间戳格式不同..ms用的是自定义的时 ...
- mysql 日期 时间戳 转换
/***************************************************************************************** * mysql 日 ...
- Mysql的 时间戳转换 和 c# 的时间戳转换 (以秒来进行转换,非毫秒,主要是mysql不能存毫秒)
Mysql 时间戳函数 => 从时间 转成 时间戳 UNIX_TIMESTAMP() 获取当前服务器时间的时间戳 UNIX_TIMESTAMP('2013-01-01 12:33:19') ...
- unix时间戳转换成标准时间(c#)
//---unix时间戳转换成标准时间(c#)---// /* string timeStamp = "1144821796"; DateTime dtSt ...
- C#将unix时间戳转换成.net的DateTime类型的代码
下面的内容是关于C#将unix时间戳转换成.net的DateTime类型的内容. DateTime epoch = new DateTime(1970,1,1,0,0,0,0, DateTimeKin ...
- 007grafana监控时间戳转换
一. https://d.jyall.me/dashboard-solo/db/soloview?panelId=1&var-metrics=stats.gauges.zookeeper.mo ...
随机推荐
- 关于Google Android平台的ClockworkMod Recovery恢复模式
lockworkMod Recovery,它也被称为Clockwork与CWM,它是装载Google Android操作系统设备的一个自定义的Recovery恢复模式,它可以使得相关Android设备 ...
- AMD64 Instruction-Level Debugging With dbx
http://www.oracle.com/technetwork/server-storage/solarisstudio/documentation/amd64-dbx-364568.html A ...
- 模拟登陆CSDN——就是这么简单
工具介绍 本篇文章主要是解说怎样模拟登陆CSDN.使用的工具是HttpClient+Jsoup 当中HttpClient主要是负责发送请求,而Jsoup主要是解析HTML 你可能对HttpClient ...
- jsondataobjects
jsondataobjects GITHUB: https://github.com/ahausladen/jsondataobjects.git 跨平台JSON库 Json Data Objects ...
- log4j.properties打印日志信息(1)
log4j.properties log4j.rootLogger=debug,stdout,logfile ### 把日志信息输出到控制台 ### log4j.appender.stdout=org ...
- JAVA nio 2 定义 Path 类
一旦确认了文件系统上的一个文件或目录,那么就可以定义一个 Path 类来指向它.定义 Path 类可以使用绝对路径.相对路径.路径中带有一个点号“.”(表示当前目录).路径中带有两个点“..”(表示上 ...
- Android之MVC——Model通知View去更新(实用)
下面两段标红加深的代码是重点: import android.app.Activity; import android.os.Bundle; import android.view.View; imp ...
- 快速近似最近邻搜索库 FLANN - Fast Library for Approximate Nearest Neighbors
What is FLANN? FLANN is a library for performing fast approximate nearest neighbor searches in high ...
- Ubuntu 常用命令大全
Ubuntu 常用命令大全查看软件 xxx 安装内容#dpkg -L xxx查找软件#apt-cache search 正则表达式查找文件属于哪个包#dpkg -S filename apt-file ...
- 混沌数学之离散点集图形DEMO
最近看了很多与混沌相关的知识,并写了若干小软件.混沌现象是个有意思的东西,同时混沌也能够生成许多有意思的图形.混沌学的现代研究使人们渐渐明白,十分简单的数学方程完全可以模拟系统如瀑布一样剧烈的行为.输 ...