.net 时间戳和日期互转

1、时间戳转日期
public static DateTime IntToDateTime(int timestamp)
{
return TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1)).AddSeconds(timestamp);
}
调用:IntToDateTime(1458637638);

输出:2016/3/22 17:7:18

2、日期转时间戳
public static DateTime DateTimeToInt(DateTime datetime)
{
return (datetime.ToUniversalTime().Ticks - new DateTime(1970, 1, 1).Ticks) / 10000000
}
调用: DateTimeToInt(DateTime.Now);

输出:1458638060

.net 时间戳和日期互转 【转】http://www.cnblogs.com/zhuiyi/p/5307540.html的更多相关文章

  1. .net 时间戳和日期互转

    1.时间戳转日期 public static DateTime IntToDateTime(int timestamp) {     ,,)).AddSeconds(timestamp); } 调用: ...

  2. PHP时间戳和日期互转换

    在php中我们要把时间戳转换日期可以直接使用date函数来实现,如果要把日期转换成时间戳可以使用strtotime()函数实现,下面我来给大家举例说明. 1.php中时间转换函数 strtotime ...

  3. MySQL时间戳与日期互转

    1.UNIX时间戳转换为日期用函数: FROM_UNIXTIME() ); 输出:2006-08-22 12:11:10 2.日期转换为UNIX时间戳用函数: UNIX_TIMESTAMP() sel ...

  4. js 时间戳和日期互转

    // 获取当前时间戳(以s为单位) var timestamp = Date.parse(new Date()); timestamp = timestamp / 1000; //当前时间戳为:140 ...

  5. Python时间戳和日期的相互转换

    Python时间戳和日期的相互转换 (2014-03-17 11:24:35) 转载▼   分类: Python 当前时间戳:time.time() 当前日期:time.ctime() 1.Pytho ...

  6. php 时间戳与日期的转换(转载)

    UNIX时间戳和格式化日期是我们常打交道的两个时间表示形式. a:Unix时间戳存储.处理方便,但是不直观 b:格式化日期直观,但是处理起来不如Unix时间戳那么自如 [关于两者的互相转换] 日  期 ...

  7. jquery 时间戳与日期转换

    (function($) { $.extend({ myTime: { /** * 当前时间戳 * @return <int> unix时间戳(秒) */ CurTime: functio ...

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

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

  9. jQuery中时间戳和日期的相互转换

    在项目中经常会使用时间戳和日期的相互转换,可以参考如下代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2 ...

随机推荐

  1. 【转载】COM:IUnknown、IClassFactory、IDispatch

    原文:COM:IUnknown.IClassFactory.IDispatch COM组件有三个最基本的接口类,分别是IUnknown.IClassFactory.IDispatch. COM规范规定 ...

  2. jquery append()详解

    1 http://www.365mini.com/page/jquery-append.htm 2 http://blog.csdn.net/chaiyining007/article/details ...

  3. change the walltime for currently running PBS job (qalter pbs)

    qalter jobid -l walltime=X e.g.qalter 377470.manager -l walltime=2222:00:00qalter: Unauthorized Requ ...

  4. DJANGO基础学习之转义总结:escape,autoescape,safe,mark_safe

    何谓转义?就是把html语言的关键字过滤掉.例如,<div>就是html的关键字,如果要在html页面上呈现<div>,其源代码就必须是<div> PS:转义其实就 ...

  5. Codeforces Round #158 (Div. 2) C. Balls and Boxes 模拟

    C. Balls and Boxes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  6. 自定义表单input

    我想实现下面这个效果?应该怎么写最方便呢?最有效,兼容性最好呢 我使用<p>标签套lable,加input的组合,p标签绝对定位,input标签铺满,用padding填充. 主要css . ...

  7. php提高程序效率的24个小技巧

    本文转自<php必须知道的300个问题>一书,在此记录方便以后查看 (1)用单引号代替双引号来包含字符串,这样做会更快些.因为php会在双引号包围的字符串中搜寻变量,单引号则不会.注意:只 ...

  8. JavaScript基础知识之——Location 对象详解

    属性 描述 location.hash 设置或取得 URL 中的锚 location.host 设置或取得 URL 中主机(包括端口号) location.hostname 设置或取得 URL 中的主 ...

  9. HDU5785 manacher+差分数组

    用manacher算法O(n)求出所有的回文半径.有了回文半径后,就可以求出L[i]表示以i结尾的回文串的起始位置的和R[i]表示以i起始的回文串的结尾位置的和,然后就可以求出答案了,这里要注意奇偶长 ...

  10. .net 连接sqlserver类库

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Da ...