using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection; namespace Common
{
public static class ExtendMethod
{
// DateTime --> long
public static long? ConvertDataTimeToLong(this DateTime? dt)
{
if (dt == null || dt == default(DateTime)) return null;
try
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(, , ));
TimeSpan toNow = dt.Value.Subtract(dtStart);
long timeStamp = toNow.Ticks;
timeStamp = long.Parse(timeStamp.ToString().Substring(, timeStamp.ToString().Length - ));
return timeStamp <= ? : timeStamp;
}
catch
{
return null;
}
} // long --> DateTime
public static DateTime? ConvertLongToDateTime(this long? d)
{
if (d == ) return null;
try
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(, , ));
long lTime = long.Parse(d + "");
TimeSpan toNow = new TimeSpan(lTime);
DateTime dtResult = dtStart.Add(toNow);
return dtResult;
}
catch
{
return null;
}
}
}
}

c#日期和时间戳互转的更多相关文章

  1. JavaScript 日期与时间戳互转

    1.时间戳转日期格式: function timestampToTime(timestamp) { var date = new Date(timestamp * 1000);//时间戳为10位需*1 ...

  2. MySQL日期与时间戳互转函数

    -- 时间戳转日期 ); #日期转时间戳 Select UNIX_TIMESTAMP('2018-07-16 12:23:00');

  3. MySQL日期 字符串 时间戳互转

    平时比较常用的时间.字符串.时间戳之间的互相转换,虽然常用但是几乎每次使用时候都喜欢去搜索一下用法:本文将作为一个笔记,整理一下三者之间的 转换(即:date转字符串.date转时间戳.字符串转dat ...

  4. 关于MYSQL日期 字符串 时间戳互转

    时间转字符串: select date_format(now(), '%Y-%m-%d'); #结果:2016-01-05 时间转时间戳: select unix_timestamp(now()); ...

  5. linux与unix时间戳互转

    linux与unix时间戳互转 今天在消费kafka数据时遇到了这样一个问题,kafka数据中所有的数据时间戳格式都是unix上时间戳的格式,例如:1505786829101,看到这个时间戳真的是头都 ...

  6. 用shell将时间字符串与时间戳互转

    date的详细用户可以参考下面的 http://www.cnblogs.com/xd502djj/archive/2010/12/29/1919478.html date 的具体用法可以查看另外一篇博 ...

  7. java 日期转时间戳,时间戳转为日期

    package date; import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Dat ...

  8. MySQL 日期和时间戳互相转换

    ① 时间戳转换成日期 FROM_UNIXTIME 例如: 数据表中 invest_time 存储的是时间戳,如 1429063399 使用 FROM_UNIXTIME 可以把时间戳转换为日期: sel ...

  9. 前端(js/jquery) 日期和时间戳的转换

    一.JavaScript中获取当前时间的时间戳 方法一: var timestamp=Date.parse(new Date()); ====>结果是:1451441086000 注:这种方式精 ...

随机推荐

  1. fjnu2019第二次友谊赛 B题

    ### 题目链接 ### 题目大意: 给你一个 n * m 的地图以及小蛇蛇头的初始位置,告诉你它会往 上.下.左.右 四个方向走.若在走的过程中(包括结束时)会使得小蛇越界,则输出 "Ga ...

  2. ETCD:运行时重新配置设计

    原文地址:the runtime configuration design 运行时重新配置是分布式系统中最难,最容易出错的部分,尤其是在基于共识(像etcd)的系统中. 阅读并学习关于etcd的运行时 ...

  3. Nginx安装及配置反向代理

    本片博客记录在ubuntu16下安装nginx,以及如何实现负载均衡 安装nginx 如果是新机器,安装相关依赖环境 sudo apt install build-essential sudo apt ...

  4. 用户APC的执行过程

    Windows内核分析索引目录:https://www.cnblogs.com/onetrainee/p/11675224.html 用户APC的执行过程 一.一个启发式问题 有一个问题,线程什么时候 ...

  5. Swoole中内置Http服务器

    创建httpServer.php文件,代码如下: <?php // 创建服务对象 $http = new swoole_http_server("10.211.55.17", ...

  6. Windows下Linux虚拟机的配置以及Win10 linux子系统开启

    本文所用资料下载地址为: 链接:链接:https://pan.baidu.com/s/1iiI2ebAnomKrBpvSg05w2A 提取码:7giz 复制这段内容后打开百度网盘手机App,操作更方便 ...

  7. HTTPS请求处理

    HTTPS请求的时候: [1]证书是受信任的,什么都不用做 [2]证书是不受信任的,是自签名的 (1)修改配置文件,禁用ATS特性 (2)信任并安装数字证书 NSURLSession的示例代码如下: ...

  8. 如何在Macbook上安装MySQL ?

    MySQL是常用的一款开源数据库,对各个平台都提供了支持,而Macbook又作为程序员的一款主力开发工具经常被使用.因此怎么在Macbook上安装MySQL进行程序开发也成了一项基本技能.下面来跟随本 ...

  9. QT无窗口状态下对键盘事件的监听

    Question:最近在搞linux下的一个客户端项目,需要接收键盘事件,但是又不能有界面,这种情况怎么处理呢? int main(int argc, char *argv[]) { QApplica ...

  10. gcc栈溢出保护机制:stack-protector

    关键词:stack-protector.stack-protector-strong.stack-protector-all等等. 1. gcc栈保护机制stack-protector简介 gcc提供 ...