/// <summary>
/// unix时间转换为datetime
/// </summary>
/// <param name="timeStamp"></param>
/// <returns></returns>
public static DateTime UnixTimeToTime(string timeStamp)
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
long lTime = long.Parse(timeStamp + "0000000");
TimeSpan toNow = new TimeSpan(lTime);
return dtStart.Add(toNow);
}

/// <summary>
/// datetime转换为unixtime
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public static int ConvertDateTimeInt(System.DateTime time)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
return (int)(time - startTime).TotalSeconds;
}

unix时间转换为datetime\datetime转换为unixtime的更多相关文章

  1. 生成二维码 加密解密类 TABLE转换成实体、TABLE转换成实体集合(可转换成对象和值类型) COOKIE帮助类 数据类型转换 截取字符串 根据IP获取地点 生成随机字符 UNIX时间转换为DATETIME\DATETIME转换为UNIXTIME 是否包含中文 生成秘钥方式之一 计算某一年 某一周 的起始时间和结束时间

    生成二维码 /// <summary>/// 生成二维码/// </summary>public static class QRcodeUtils{private static ...

  2. C# 获取北京时间 (根据纪元时间(1970/1/1)转换为DateTime)

    根据纪元时间(1970/1/1)转换为DateTime WebClient wc = new WebClient(); s= wc.DownloadString("http://api.ti ...

  3. c# dateTime格式转换为Unix时间戳工具类

    using System; using System.Collections.Generic; using System.Text; namespace TJCFinanceWriteOff.BizL ...

  4. Unix时间戳与C# DateTime时间类型互换

    Unix时间戳最小单位是秒,开始时间为格林威治标准时间1970-01-01 00:00:00ConvertIntDateTime方法的基本思路是通过获取本地时区表示Unixk开始时间,加上Unix时间 ...

  5. datetime.datetime.today()生成时间转换成unixtime

    首先要将时间中秒后面的.及其以后的部分去掉,否则时间转换函数 currenttime=str((datetime.datetime.today())).split('.',2)[0] str((dat ...

  6. 机器学习入门-随机森林温度预测的案例 1.datetime.datetime.datetime(将字符串转为为日期格式) 2.pd.get_dummies(将文本标签转换为one-hot编码) 3.rf.feature_importances_(研究样本特征的重要性) 4.fig.autofmt_xdate(rotation=60) 对标签进行翻转

    在这个案例中: 1. datetime.datetime.strptime(data, '%Y-%m-%d') # 由字符串格式转换为日期格式 2. pd.get_dummies(features)  ...

  7. NotSupportedException-无法将类型“System.DateTime”强制转换为类型“System.Object”

    几张图就可以说明一切 2015-03-29 21:54:09,206 [77] ERROR log - System.NotSupportedException: 无法将类型“System.DateT ...

  8. Android时间戳转换为标准Datetime(yyyy-MM-dd hh:mm:ss)格式

    下列函数为实现过程,已经测试通过. /// <summary> /// Android时间戳转换为标准Datetime /// </summary> /// <param ...

  9. 【測试工具】一个将Unix时间转换为通用时间的工具

    一个将Unix时间转换为通用时间的工具 演示效果: 点击转换之后变为: 源码: function calctime2(){ var time = window.document.getElementB ...

随机推荐

  1. cadence焊盘及元件封装制作

    前面学习了元件封装的制作,由于琐碎事情的耽误,加上学习python,没有及时的总结这部分内容,现在做一个补充!

  2. python scrapy框架爬取豆瓣

    刚刚学了一下,还不是很明白.随手记录. 在piplines.py文件中 将爬到的数据 放到json中 class DoubanmoviePipelin2json(object):#打开文件 open_ ...

  3. 《Android插件化开发指南》面世

    本书在京东购买地址:https://item.jd.com/31178047689.html 本书Q群:389329264 (一)这是一本什么书 如果只把本书当作纯粹介绍Android插件化技术的书籍 ...

  4. C++ : cin.get()函数和cin函数的使用

    笔者由于自己忘记了cin函数怎么用,所以这里趁自己复习C++的空子正好可以做做记录. 1.cin>>          用法1:最基本,也是最常用的用法,输入一个数字: #include ...

  5. Kubernetes — 我的第一个容器化应用

    而在这篇文章中,我们就来扮演一个应用开发者的角色,使用这个 Kubernetes 集群发布第一个容器化应用. 在开始实践之前,我先给你讲解一下 Kubernetes 里面与开发者关系最密切的几个概念. ...

  6. [Swift]LeetCode818. 赛车 | Race Car

    Your car starts at position 0 and speed +1 on an infinite number line.  (Your car can go into negati ...

  7. [Swift]LeetCode917. 仅仅反转字母 | Reverse Only Letters

    Given a string S, return the "reversed" string where all characters that are not a letter  ...

  8. Spring Boot 面试题

    1.列举一些SpringBoot特性 1.创建独立的Spring项目 2.内置Tomcat和Jetty容器 3.提供一个starter POMs来简化Maven配置 4.提供了一系列大型项目中常见的非 ...

  9. 定时任务 winform开发

    在项目中我们经常遇到与时间结合的无限或者有限轮回的任务.例如每月一号统计工作量,基本这种情况,都会是设置定时任务,定时执行.好了,下面就记录一下定时任务的开发吧. 首先描述一下开发思路: 建立一个wi ...

  10. PyCharm2019 激活码

    因公司的需求,需要做一个爬取最近上映的电影.列车号.航班号.机场.车站等信息,所以需要我做一个爬虫项目,当然java也可以做爬虫,但是还是没有python这样方便,所以也开始学习Python啦!!! ...