DateTime与long互转
DateTime转long:
public static long GetDateLong(object time)
{
DateTime epoc = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(, , ));
TimeSpan delta = new TimeSpan(); if (time is DateTime)
delta = ((DateTime)time).Subtract(epoc); else if (time is string)
delta = DateTime.Parse(time.ToString()).Subtract(epoc); else
throw new ArgumentOutOfRangeException("时间格式错误.1"); if (delta.TotalMilliseconds < )
throw new ArgumentOutOfRangeException("时间格式错误.2"); long ticks = (long)delta.TotalMilliseconds;
return ticks;
}
long转DateTime:
public static DateTime GetDateFromLong(long ticks)
{
var date = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(, , ));
date = date.AddMilliseconds(ticks);
return date;
}
网上常见错误:
DateTime epoc = new DateTime(, , );
DateTime与long互转的更多相关文章
- C#技术点--修改系统时间
C#的System.DateTime类提供了对日期时间的封装,用它进行时间的转换和处理很方便,但是我没有在其中找到任何可以用来修改系统时间的成员.用过VC.VB等的朋友可能知道,我们可以调用Win32 ...
- python 时间感觉能用到的
datetime, string, timestamp 互转 import time import datetime print datetime.datetime.now() print datet ...
- python 中date datetime time 与str的互转
以下全部引入 form datetime import datetime, timedelta import time 一.time 转str 二.datetime 转 str str_date = ...
- MSSQL中datetime与unix时间戳互转
//ms sql datetime 转unix时间戳 SELECT DATEDIFF(s, '19700101',GETDATE()) //ms sql unix时间戳 转datetime 涉及到时区 ...
- C# 时间戳与DateTime互转
#region 转换时间为unix时间戳 /// <summary> /// 转换时间为unix时间戳 /// </summary> /// <param name=&q ...
- Mysql 中日期类型bigint和datetime互转
MySql数据库中字段类型bigint 长度是10位的 mysql> select (from_unixtime(1554047999))as datatime;+--------------- ...
- XML 和 List 互转类
XML 和 List 互转类 using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- .net 时间戳和日期互转 【转】http://www.cnblogs.com/zhuiyi/p/5307540.html
.net 时间戳和日期互转 1.时间戳转日期public static DateTime IntToDateTime(int timestamp){ return TimeZone.CurrentTi ...
- python(6)时间戳和北京时间互转,输出当前的时间和推到七天前的日期
项目发展的需要:(包含时间函数)time datetime 时间戳和北京时间互转 import time import datetime s = '2015-04-17 11:25:30' d = d ...
随机推荐
- 服务器宕机,mysql无法启动,job for mysql.service failed because the process exited with error code,数据库备份与恢复
[问题现象] 服务器在运行过程中,因人为意外导致电源被拔,服务器宕机,mysql重启不成功,报错如下 根据提示,输入systemctl status mysql.service和journalctl ...
- spring事物回滚机制 (事务异常回滚,捕获异常不抛出就不会回滚)
当异常被捕获catch的时候,spring的事物则不会回滚 为什么不会滚呢?? spring aop 异常捕获原理:被拦截的方法需显式抛出异常,并不能经任何处理,这样aop代理才能捕获到方法的异常 ...
- values.xml:3:5-58:857: AAPT: error: resource android:attr/fontVariationSettings not found.
修改app/build.gradle中的版本 compileSdkVersion 28 targetSdkVersion 28 具体不知道为何要修改为28,但在android/build.gradle ...
- Java - 一道关于Arrays.asList的题目
题目 有这样一道有趣的题目: final int[] test = new int[]{1,2,3,4}; final Integer[] test2 = new Integer[]{1,2,3,4} ...
- 湖南大学新生赛C,G,J题解
C: 思路:做几组数据就基本能发现规律,奇数为-1,偶数为1 代码: #include<cstdio> #include<iostream> #include<cstri ...
- Rebus消息总线
这里主要讲一下我基于Rebus写的一个ABP框架的模块 目录结构 对于Rebus网上的资料很少,其实我对于服务总线也不是很理解 ..个人理解的就是像ABP中的EventBus那样的,但是集成了一些 ...
- zabbix agent 配置
http://blog.csdn.net/z644041867/article/details/76618644 https://www.cnblogs.com/miclesvic/p/6144924 ...
- windows环境下memcache配置方法 详细篇
将memcache服务器安装包解压到C:\memcached文件夹后,使用cmd命令窗口安装. 1>开始>运行:CMD(确定) 2>cd C:\memcached(回车) 3> ...
- MySQL存储过程多条修改语句
DROP procedure Sel_Function_ActivityPastDueDELIMITER $$DROP procedure IF EXISTS`shouyi`.`Sel_Functio ...
- ArrayList 练习题
1点名器 import java.util.ArrayList; import java.util.Random; import java.util.Scanner; class CallName3 ...