C# DateTime时间格式转换为Unix时间戳格式
double ntime=dateTimeToUnixTimestamp(DateTime.Now);
long g1 = GetUnixTimestamp();
long g2 = ConvertDateTime2Long(DateTime.Now);
public double dateTimeToUnixTimestamp(DateTime datetime)
{
return (datetime - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds/10000;
}
string date = DateTime.Now.AddYears(-20).ToString("yyyy-MM-dd HH:mm:ss");
1995-11-05 20:15:37
/// <summary>
/// 将c# DateTime时间格式转换为Unix时间戳格式
/// </summary>
/// <param name="time">时间</param>
/// <returns>long</returns>
public long ConvertDateTime2Long(System.DateTime time)
{
DateTime timeStamp = new DateTime(1970, 1, 1); //得到1970年的时间戳
long a = (time.ToUniversalTime().Ticks - timeStamp.Ticks) / 10000000; //注意这里有时区问题,用now就要减掉8个小时
return a;
}
//获取当前时间的时间戳
public long GetUnixTimestamp()
{
DateTime timeStamp = new DateTime(1970, 1, 1); //得到1970年的时间戳
long a = (DateTime.UtcNow.Ticks - timeStamp.Ticks) / 10000; //注意这里有时区问题,用now就要减掉8个小时
return a;
}
//
long temp = GetUnixTimestamp();
DateTime tamp = GetTime(Convert.ToString(temp)); /// <summary>
/// c# to unix
/// </summary>
/// <returns></returns>
public static long GetUnixTimestamp()
{
DateTime timeStamp = new DateTime(, , ); //得到1970年的时间戳
long a = (DateTime.UtcNow.Ticks - timeStamp.Ticks) / ; //注意这里有时区问题,用now就要减掉8个小时
return a;
}
/// <summary>
/// unix to c#
/// </summary>
/// <param name="timeStamp"></param>
/// <returns></returns>
public static DateTime GetTime(string timeStamp)
{
DateTime dtStart = new DateTime(, , ); //得到1970年的时间戳
long lTime = long.Parse(timeStamp + "");
TimeSpan toNow = new TimeSpan(lTime);
DateTime temp=dtStart.Add(toNow);
System.TimeSpan duration = new System.TimeSpan(, , , );
System.DateTime answer = temp.Add(duration);
return answer;
}
C# DateTime时间格式转换为Unix时间戳格式的更多相关文章
- DateTime时间格式转换为Unix时间戳格式
/// <summary> /// 将DateTime时间格式转换为Unix时间戳格式 /// </summary> /// <param name="date ...
- [工具类]将时间转换为unix时间戳格式
写在前面 由于在数据库中存的时间有时间戳格式的数据,在解析以及保存的时候,就需要考虑到数据格式的兼容性问题.看到数据库中的时间字段基本上都是以时间戳格式存储的,没办法,只能将时间进行转换了,考虑到其他 ...
- c# dateTime格式转换为Unix时间戳工具类
using System; using System.Collections.Generic; using System.Text; namespace TJCFinanceWriteOff.BizL ...
- c# datetime与 timeStamp(unix时间戳) 互相转换
/// <summary> /// Unix时间戳转为C#格式时间 /// </summary> /// <param name="timeStamp" ...
- c# DateTime时间格式和JAVA时间戳格式相互转换
/// java时间戳格式时间戳转为C#格式时间 public static DateTime GetTime(long timeStamp) { DateTime dtStart = TimeZon ...
- MySql 格式化时间(包括正常时间格式与unix时间戳的互相转换)
函数:FROM_UNIXTIME 作用:将MYSQL中以INT(11)存储的时间以"YYYY-MM-DD"格式来显示.语法:FROM_UNIXTIME(unix_timestamp ...
- 将windows文本格式转换为UNIX格式
将windows文本格式转换为UNIX格式 1.使用sed命令来进行转换,如下: sed -e ’s,^M,,g’ textfile 其中^M的输入方法是Ctrl+V, Ctrl+M 对于批量文件的处 ...
- Jquery实现日期转换为 Unix时间戳及时间戳转换日期
(function ($) { $.extend({ myTime: { /** * 当前时间戳 * @return <int> unix时间戳(秒) */ CurTime: functi ...
- Swagger--解决日期格式显示为Unix时间戳格式 UTC格式
在swagger UI模型架构上,字段日期显示为“日期”:“2018-10-15T09:10:47.507Z”但我需要将其作为“日期”:“2018-9-26 12:18:48”. tips:以下这两种 ...
随机推荐
- django-cms安装
ubuntu:12.04 (32bit) djangocms 0.5.1 =========================== 首先,跟着这个做: https://github.com/divio/ ...
- IDEA 进入到项目的系统文件路径
选中项目,单击右键,在弹出的菜单中点击file path
- Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the differen ...
- zookeeper部署及集群测试
zookeeper部署及集群测试 环境 三台测试机 操作系统: centos7 ; hostname: c1 ; ip: 192.168.1.80 操作系统: centos7 ; hostname: ...
- 【转】你可能不知道的Shell
本文转自http://coolshell.cn/articles/8619.html,只摘取了其中的一部分. 再分享一些可能你不知道的shell用法和脚本,简单&强大! 在阅读以下部分前,强烈 ...
- python迭代器与iter()函数实例教程
python迭代器与iter()函数实例教程 发布时间:2014-07-16编辑:脚本学堂 本文介绍了python迭代器与iter()函数的用法,Python 的迭代无缝地支持序列对象,而且它还允许程 ...
- linux琐碎知识点
1.awk的使用方式,pattern支持正则表达式 awk 'pattern{action}' {filenames} 其中 pattern 表示 AWK 在数据中查找的内容,而 action 是在找 ...
- android volley http请求框架
2015年11月6日 14:35:19 注意: 1.安卓官方的volley在google的codesource上, 在github上有他的镜像android-volley, 并解决了官方的一部分bug ...
- ffmpeg-20160726-bin.7z
ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...
- ffmpeg-20160506-git-bin
ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...