js、 sql、 C#时间、时间戳相互转换

//1.获取当前时间戳_c#
long aa = (DateTime.Now.ToUniversalTime().Ticks - ) /
//2.时间戳->时间 C#
DateTime b11 = GetTime("");//11位时间戳->时间
DateTime b13 = ConvertStringToDateTime("");//13 位时间戳->时间
//3. 时间->时间戳C#
int a11= ConvertDateTimeInt(b11);//11 位 时间->时间戳
long a13 = ConvertDateTimeToInt(b13);//13位 时间->时间戳
 private DateTime GetTime(string timeStamp)    //11 时间戳转为C#格式时间
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(, , ));
long lTime = long.Parse(timeStamp + "");
TimeSpan toNow = new TimeSpan(lTime); return dtStart.Add(toNow);
}
private int ConvertDateTimeInt(System.DateTime time) //11 DateTime时间格式转换为Unix时间戳格式
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(, , ));
return (int)(time - startTime).TotalSeconds;
} public static long ConvertDateTimeToInt(System.DateTime time) ////13 位 时间转为时间
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(, , , , , , ));
long t = (time.Ticks - startTime.Ticks) / ; //除10000调整为13位
return t;
} private DateTime ConvertStringToDateTime(string timeStamp) //13位时间戳转为C#格式时间
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(, , ));
long lTime = long.Parse(timeStamp + "");
TimeSpan toNow = new TimeSpan(lTime);
return dtStart.Add(toNow);
}

sql

 --1当前时间戳 获取sql
SELECT DATEDIFF(S,'1970-01-01 00:00:00', GETDATE()) - 8 * 3600
SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE())
--2时间戳→普通时间sql
SELECT DATEADD(s,1483461862,'1970-01-01 08:00:00') as DTime
SELECT DATEADD(S,1483461862 + 8 * 3600,'1970-01-01 00:00:00')
--3 普通时间 → Unix时间戳sql
SELECT DATEDIFF(s, '1970-01-01 08:00:00', '2017-01-04 00:44:22.000')

js

1当前时间戳 获取js
Math.round(new Date().getTime()/1000)
2时间戳→普通时间js
var unixTimestamp = new Date(Unix timestamp * 1000);
var commonTime =unixTimestamp.toLocaleString();
3 普通时间 → Unix时间戳js
var commonTime = new Date(Date.UTC(year, month - 1, day, hour, minute, second))

js sql C#时间、时间戳相互转换的更多相关文章

  1. js日期格式与时间戳相互转换

    本文转自:https://blog.csdn.net/Lc_style/article/details/80626748 1.将日期格式转化为时间戳: var date = new Date('201 ...

  2. 字符串时间与Unix时间戳相互转换

    字符串时间与Unix时间戳相互转换 /** * @Author: wangkun * @Date : 2016/1/21 13:43 * @Description : 字符串时间转换为Unix时间戳 ...

  3. js和php的时间戳和时间的转化

    js时间戳转化为时间 //时间戳转时间 function time(sj) { var now = new Date(sj*1000); var year =now.getFullYear(); va ...

  4. python正常时间和unix时间戳相互转换的方法

    python正常时间和unix时间戳相互转换的方法 本文实例讲述了python正常时间和unix时间戳相互转换的方法.分享给大家供大家参考.具体分析如下: 这段代码可以用来转换常规时间格式为unix时 ...

  5. SQL Server时间粒度系列----第3节旬、月时间粒度详解

    本文目录列表: 1.SQL Server旬时间粒度2.SQL Server月有关时间粒度 3.SQL Server函数重构 4.总结语 5.参考清单列表   SQL Server旬时间粒度       ...

  6. SQL Server时间粒度系列----第4节季、年时间粒度详解

    本文目录列表: 1.SQL Server季时间粒度2.SQL Server年时间粒度 3.总结语 4.参考清单列表   SQL Serve季时间粒度       季时间粒度也即是季度时间粒度.一年每3 ...

  7. piap.excel 微软 时间戳转换mssql sql server文件时间戳转换unix 导入mysql

    piap.excel 微软 时间戳转换mssql sql server文件时间戳转换unix 导入mysql 需要不个mssql的sql文件导入mysql.他们的时间戳格式不同..ms用的是自定义的时 ...

  8. iOS标准时间与时间戳相互转换

    iOS标准时间与时间戳相互转换 (2012-07-18 17:03:34) 转载▼ 标签: ios 时间戳 标准时间 格式 设置 转化 杂谈 分类: iPhone开发 设置时间显示格式:     NS ...

  9. 小程序 js中获取时间new date()的用法(网络复制过来自用)

    js中获取时间new date()的用法   获取时间: 1 var myDate = new Date();//获取系统当前时间 获取特定格式的时间: 1 myDate.getYear(); //获 ...

随机推荐

  1. iOS10 导航条,这个二狗子变了...踩坑

    1.iOS10导航透明要转换一个透明image UIImage *image = IsDeviceVersionIOS10 ? [WeUtils imageWithColor:[UIColor cle ...

  2. imx6 关闭调试串口

    需要关闭imx6调试串口,用作普通的串口使用. 参考链接 http://blog.csdn.net/neiloid/article/details/7585876 http://www.cnblogs ...

  3. C# LINQ

    Sorting: OrderBy ThenBy OrderByDescending ThenByDescending Reverse public IEnumerable<Customer> ...

  4. CORS浏览器跨域

    在SO上发现一个解释跨域很棒的,忍不住拿过来 链接在此:http://stackoverflow.com/questions/10636611/how-does-access-control-allo ...

  5. java8 学习系列--NIO学习笔记

    近期有点时间,决定学习下java8相关的内容: 当然了不止java8中新增的功能点,整个JDK都需要自己研究的,不过这是个漫长的过程吧,以自己的惰性来看: 不过开发中不是有时候讲究模块化开发么,那么我 ...

  6. Warning C4819

    VC工程里有个文件,只有文件里写了汉字,就报警告C4819 Warning C4819:The file contains a character that can ot be represented ...

  7. NSURLSession访问网络数据

    1.NSMutableURLRequest的设置 //创建NSMutableURLRequest对象 NSMutableURLRequest *request = [NSMutableURLReque ...

  8. Excel Note

    公式的引用分为相对引用.绝对引用和混合引用.如果要使公式中的引用随着公式的下拉改变就用相对引用.如=sum(A2:D20),这个公式下拉时引用的单元格就会随着变化.如果要使公式中的引用下拉时不会改变就 ...

  9. Apache与Tomcat的整合

    一 Apache与Tomcat比较联系 apache支持静态页,tomcat支持动态的,比如servlet等. 一般使用apache+tomcat的话,apache只是作为一个转发,对jsp的处理是由 ...

  10. Easy Tag Write(2)

    package skyseraph.android.util.nfc; import com.google.common.collect.BiMap; import com.google.common ...