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 ...
随机推荐
- Request a certificate from a certificate vendor
Request a certificate from a certificate vendor Now, with your CSR in hand, visit the Web site of yo ...
- 利用 Docker 包 Laradock 服务器部署 Laravel & ThinkSNS+ 等程序实战(多项目)
什么是ThinkSNS+ ThinkSNS(简称TS),一款全平台综合性社交系统,为国内外大中小企业和创业者提供社会化软件研发及技术解决方案,目前最新版本为ThinkSNS+.ThinkSNS V4. ...
- 链家H5项目总结
在此次项目中,使用的是高度百分比.对于适配这一块确实少了很多. 1.如果是用高度百分比的话.则img需要写成这样的样式. img{ width:auto; height:100%; display: ...
- python序列化模块 json&&pickle&&shelve
#序列化模块 #what #什么叫序列化--将原本的字典.列表等内容转换成一个字符串的过程叫做序列化. #why #序列化的目的 ##1.以某种存储形式使自定义对象持久化 ##2.将对象从一个地方传递 ...
- Codeforces 548E(莫反、容斥)
转化为质数域上的操作,如果用莫反的话,记录因数的cnt. 其实莫反的推式子最后和容斥做法殊途同归了,容斥的系数就是莫比乌斯函数. const int maxn = 2e5 + 5, maxa = 5e ...
- 牛客小白月赛13 G(双向搜索)
AC通道 两边同步搜,一步里面A走一次B走两次,遇到对方走过的地方就得到了答案. #include <bits/stdc++.h> using namespace std; const i ...
- shell 发送Post请求,并获取状态码
#!/bin/bash aa=$ result=$(curl -H "Content-type: application/json" -X POST -o /dev/null -s ...
- setState异步函数
changeLeader(value){ console.log(value) this.setState({ leader:value },() => { console.lo ...
- SSIS父子维度
1.数据仓库结构: 2.区域的AttributeHierarchyVisible设置为False 3.Parent ID的Usage设置为Parent 4.级别命名: 5.结果:
- 浅析libuv源码-node事件轮询解析(3)
好像博客有观众,那每一篇都画个图吧! 本节简图如下. 上一篇其实啥也没讲,不过node本身就是这么复杂,走流程就要走全套.就像曾经看webpack源码,读了300行代码最后就为了取package.js ...