C# Unix时间戳和DateTime类型相互转换
/// <summary>
/// 将Unix时间戳转换为DateTime类型时间
/// </summary>
/// <param name="d">double 型数字</param>
/// <returns>DateTime</returns>
public static System.DateTime ConvertIntDateTime(double d)
{
System.DateTime time = System.DateTime.MinValue;
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
time = startTime.AddMilliseconds(d);
return time;
} /// <summary>
/// 将c# DateTime时间格式转换为Unix时间戳格式
/// </summary>
/// <param name="time">时间</param>
/// <returns>long</returns>
public static long ConvertDateTimeInt(System.DateTime time)
{
//double intResult = 0;
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970,1,1,0,0,0,0));
//intResult = (time- startTime).TotalMilliseconds;
long t = (time.Ticks - startTime.Ticks)/10000; //除10000调整为13位
return t;
}
C# Unix时间戳和DateTime类型相互转换的更多相关文章
- Asp.Net Unix时间戳和DateTime类型转换
using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System. ...
- mysql关联修改SQL及long与datetime类型相互转换
1.关联修改 #解决思路 UPDATE tb1,tb2 SET tb1.address=tb2.address WHERE tb1.name=tb2.name UPDATE car c,tmpcolo ...
- SQL 时间戳转DateTime类型
最近在工作中通过接口获取时间字段为时间戳的值,直接入库后再页面查询时间格式时候需要通过SQL语句将时间戳格式装换为时间格式进行比较,首先我们需要知道时间戳格式是怎么产生的,: Unix时间戳(Unix ...
- oracle将unix 时间戳转换为date类型
select to_date('19700101','yyyyMMdd')+numtodsinterval(8*3600,'second')+numtodsinterval(60,'second') ...
- c# 时间戳转换为Datetime类型的时间
private static DateTime GetConvertTime(long ltime) { DateTime dt_time=new DateTime(1970,1,1,8,0,0,0) ...
- Unix时间戳与C# DateTime时间类型互换
Unix时间戳最小单位是秒,开始时间为格林威治标准时间1970-01-01 00:00:00ConvertIntDateTime方法的基本思路是通过获取本地时区表示Unixk开始时间,加上Unix时间 ...
- [开发笔记]-unix时间戳、GMT时间与datetime类型时间之前的转换
前段时间项目中涉及到了MySql和MsSql数据类型之间的转换,最近又在研究新浪微博的API,涉及到了带有时区的GMT时间类型的转换,所以,特记录于此,以备日后查询. 一:UNIX时间戳与dateti ...
- UNIX 时间戳 C#
/// 将Unix时间戳转换为DateTime类型时间 /// </summary> /// <param name="d">double 型数字</ ...
- python datetime和unix时间戳之间相互转换
python datetime和unix时间戳之间相互转换 1.代码: import time import datetime # ...
随机推荐
- mac电脑如何快速显示桌面及切换应用
使用mac电脑时,我们习惯打开很多应用,文档等等.如果打开应用非常多,需要操作桌面,却不知如何快速返回桌面和切换应用时,操作就非常不便了,下面简单介绍mac电脑系统如何快速显示桌面及切换应用? 工具/ ...
- Can I prevent the Firefox developer tools network panel from clearing on page reload?
Can I prevent the Firefox developer tools network panel from clearing on page reload? I couldn't fin ...
- HBase-概述
一种分布式.可扩展.支持海量数据存储的 NoSQL 数据库. 逻辑上,HBase 的数据模型同关系型数据库很类似,数据存储在一张表中,有行有列.但从 HBase 的底层物理存储结构(K-V)来看,HB ...
- nodejs做中间层,转发请求
简述node中间层的优势 node中间层,可以解决前端的跨域问题,因为服务器端的请求是不涉及跨域的,跨域是浏览器的同源策略导致的,关于跨域可以查看跨域复习使用node坐中间层,方便前后端分离,后端只需 ...
- 用户登录之asp.net cookie的写入、读取与操作
页面前面: <div id="login" runat="server"> <span class="log_title" ...
- angular绑定数据
Angular 中使用{{}}绑定业务逻辑里面定义的数据 <h1> Welcome to {{ title }}! /*引入title*/ </h1> export class ...
- SQL语言Select经典语句
-- 示例数据 Select * From Employee Select * From Department -- 返回工资最高的员工的信息 Select * From Employee where ...
- Python - celery 相关报错 - AttributeError: type object '_multiprocessing.win32' has no attribute 'WAIT_OBJECT_0'
报错场景 执行 celery worker -A tasks -l INFO 打开 worker 的时候报错无法进行 报错解决 Celery 的版本过高, 进行降级处理即可 pip instal ...
- web框架之MVC/MTV
MVC框架 MVC 是一种使用 MVC(Model View Controller 模型-视图-控制器)设计创建 Web 应用程序的模式 Model(模型)表示应用程序核心(比如数据库记录列表) Vi ...
- Python 解析式、生成器
标准库datetime datetime模块 对日期.时间.时间戳的处理 datetime类 类方法 today() 返回本地时区当前时间的datetime对象 now(tz=None) 返回当前时间 ...