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. SQl Server 中的decimal( m , n )的意思

    create table sc( cno ), sno ), grade ,), primary key(cno,sno), foreign key(cno) references cou(cno), ...

  2. [译]Vulkan教程(31)加载模型

    [译]Vulkan教程(31)加载模型 Loading models 加载模型 Introduction 入门 Your program is now ready to render textured ...

  3. Linux使用之centos下安装Java环境并运行Java程序

    前言 在Java中所有的程序都是在JVM上运行的.Java虚拟机(JVM)读取并处理经过编译的与平台无关的*.class文件.因为Java语言源程序编写后,先使用Java伪编译器进行伪编译,将其转换为 ...

  4. SpringBoot控制台版图书借阅程序

    // 实验存档... 效果图: 完整程序:https://pan.baidu.com/s/1-d1J90dkEtM0WKkABu0K0Q 提取码:hcnm DAO层代码由MyBatis Generat ...

  5. C sharp #002# 结构化编程基础

    饮水思源:金老师的自学网站.C# Guide 索引 变量与数据类型 C#中For each的写法 C#控制台程序编程技巧 简易图片浏览器 BigInteger以及浮点数的比较 一.变量与数据类型 us ...

  6. Python自动发送邮件--smtplib模块

    import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText f ...

  7. SAP 销售订单交货对成本中心记账

    销售订单发货不计入主营业务成本,而是直接接入费用科目,与成本中心挂钩的业务经常发生.不少公司只是简单地处理交货,计入主营业务成本,然后财务再手工将成本归结到相关的成本中心.其实SAP系统是支持销售订单 ...

  8. IDEA org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

    引用地址:https://guozh.net/idea-org-apache-ibatis-binding-bindingexception-invalid-bound-statement-not-f ...

  9. 前端JSON请求转换Date问题

    目的:记录使用SpringMVC中前端JSON数据中的日期转换成Date数据类型时区产生的问题 记录下遇到过的问题 在使用SpringMVC框架中,使用@RequestBody注解将前端的json数据 ...

  10. go语言设计模式之factory

    factory.go package factory import ( "errors" "fmt" ) const ( Cash = 1 DebitCard ...