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:以下这两种 ...
随机推荐
- Linux Vsftpd 连接超时解决方法
Linux Vsftpd 连接超时解决方法 2013-11-13 10:58:34| 分类: 默认分类|举报|字号 订阅 解决方法(http://www.lingdus.com/thread ...
- Unity3d 制作动态Mesh且可以随地面凹凸起伏
适用情景:主角带着光环,光环用一张贴图,要贴在地面上,并且随地面凹凸起伏 //代码 using UnityEngine; using System.Collections; [RequireCompo ...
- mysql备份与还原
一.直接拷贝数据库文件 直接拷贝数据库文件一般是使用文件系统备份工具cp,适合小型数据库,是最可靠的. 当你拷贝数据库文件时,必须保证表没有正在使用.如果服务器在你拷贝一个表的时候改变这个表,拷贝就失 ...
- ACM/ICPC 之 BFS+状态压缩(POJ1324(ZOJ1361))
求一条蛇到(1,1)的最短路长,题目不简单,状态较多,需要考虑状态压缩,ZOJ的数据似乎比POj弱一些 POJ1324(ZOJ1361)-Holedox Moving 题意:一条已知初始状态的蛇,求其 ...
- Linux(CentOS、Ububtu)一键安装Openstack及其它参考文档汇总
原文链接 http://www.aboutyun.com/thread-10920-1-1.html openstack相关资料 CentOS下一键安装Openstack http://blog. ...
- manage account
#!/bin/bash # #Delete_user - Automates the steps to remove an account # ############################ ...
- 【leetcode】Max Points on a Line(hard)☆
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
- 【leetcode】Rotate Image(middle)
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- jquery[siblings]取得一个包含匹配的元素集合中每一个元素的所有唯一同辈元素的元素集合
取得一个包含匹配的元素集合中每一个元素的所有唯一同辈元素的元素集合,用于筛选同辈元素的表达式 $("#pageList").click(function(){ $(this).pa ...
- XLL 框架库中的函数
这个框架库,可以让编写 XLL 更加容易.包含了管理 XLOPER/XLOPER12 内存的简单函数,创建临时 XLOPER/XLOEPR12 ,强制调用回调函数 (Excel4,Excel4v,Ex ...