C# Unix时间戳和DateTime类型相互转换
2024-09-01 14:57:13
/// <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;
}
最新文章
- zk textbox 更改字体大小及高度
- ExpressJs server中Router的设置
- lua class(table)
- Restfull API 示例
- (CodeForces 558C) CodeForces 558C
- 百度地图LBS应用开发代码
- WCF - Versus Web Service
- Java Dom解析xml
- 让EditPlus支持SQL高亮提示
- JAVA中JPA的主键自增长注解设置
- Axure RP初学2
- Spring MVC流程
- all-document
- PHP 对象转数组 Object转array
- linux-ubuntu 下R无法安装rjava模块的原因及解决方案
- 《Flask Web开发实战:入门、进阶与原理解析(李辉著 )》PDF+源代码
- SQL语句(十四)子查询
- 《剑指offer》第二十九题(顺时针打印矩阵)
- 在am中定义消息集束,并在CO中验证之后抛出异常。
- postman 获取时间戳的方法 和md5加密的方法
热门文章
- Laravel 加载第三方类库的方法
- Hive SQL NVL 相关函数
- c3p0数据库连接池 原创: Java之行 Java之行 5月8日 一、连接池概述 实际开发中“获得连接”或“释放资源”是非常消耗系统资源的两个过程
- android APP国际化一键切换实现
- 第二十章 无状态Web应用集成——《跟我学Shiro》
- git 创建标签推送远程分支
- 股票PE的应用
- 【数据库开发】在Windows上和Linux上配置MySQL的过程
- Android_7.1.1_r6源码编译
- eNSP——配置全局地址池的DHCP