convert-Csharp-DateTime-Ticks-to-js
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
var b = formatDate(636371998735052582);
document.write(b);
} //格式化时间
function formatDate(ticks) {
//var ticks = 635556672000000000; //ticks are in nanotime; convert to microtime
var ticksToMicrotime = ticks / 10000; //ticks are recorded from 1/1/1; get microtime difference from 1/1/1/ to 1/1/1970
var epochMicrotimeDiff = Math.abs(new Date(0, 0, 1).setFullYear(1)); //new date is ticks, converted to microtime, minus difference from epoch microtime
var now = new Date(ticksToMicrotime - epochMicrotimeDiff);
var year = now.getFullYear();
var month = now.getMonth() + 1;
var date = now.getDate();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second; } </script>
</head> <body>
<button onclick="myFunction()">点击这里</button>
</body>
</html>
显示结果 2017-8-1 15:57:53
convert-Csharp-DateTime-Ticks-to-js的更多相关文章
- C#中DateTime.Ticks属性及Unix时间戳转换
1.相关概念 DateTime.Ticks:表示0001 年 1 月 1 日午夜 12:00:00 以来所经历的 100 纳秒数,即Ticks的属性为100纳秒(1Ticks = 0.0001毫秒). ...
- 使用SQL生成DateTime.Ticks
在项目中我需要使用到一个随机数(Random Number),该随机数将作为 Hashtable 中的 Key 用于唯一索引数据,所以需要保持单机唯一性. 同时该随机数还需要具备可排序性以便对数据进行 ...
- SQL Server使用convert对datetime日期数据进行获取
来源:http://database.51cto.com/art/201007/211883.htm 备注:本文的语法讲解确实是比较乱,似乎格式不太严谨.参考时还是以实例验证为准比较好 以下的文章主要 ...
- C#中DateTime.Ticks
DateTime.Ticks:表示0001 年 1 月 1 日午夜 12:00:00 以来所经历的 100 纳秒数,即Ticks的属性为100纳秒(1Ticks = 0.0001毫秒). Unix时间 ...
- how to convert Map to Object in js
how to convert Map to Object in js Map to Object just using the ES6 ways Object.fromEntries const lo ...
- MySQL Unable to convert MySQL datetime value to System.DateTime 解决方案
Unable to convert MySQL date/time value to System.DateTime 解决方案 这个问题发生在MySQL数据里面有Date类型数据,在C#中查询出来时候 ...
- SQL Server 中使用 convert 转换 datetime 格式示例
Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AMSelect CONVERT(varchar(100), GETDATE() ...
- C#获取本周、上周、本月、上月、本季度、上季度、本年、上一年起始时间和结束时间
/// 取得某月的第一天 /// </summary> /// <param name="datetime">要取得月份第一天的时间</param&g ...
- C# 根据年、月、周、星期获得日期等
原文:C# 根据年.月.周.星期获得日期等 /// 取得某月的第一天 /// </summary> /// <param name="datetime">要 ...
- JS、C#及SQL中的DateTime
一:SQL中的DataTime 1. between and 相当于>= and <= 2. 常用的将DataTime查询成字符串的方法 Select CONVER ...
随机推荐
- gpu 显卡 本质
根据一切皆文件的理念,显卡.gpu.显示器是特殊的单向的只写文件.
- Linux学习总结(七)-磁盘管理 du df fdisk
一 命令df df,即disk free,可用来查看当前系统的挂载情况,也可以用来查看整体磁盘的使用情况df 不带参数,默认以KB单位显示df -i -----查看inodes 使用情况,要清楚理解i ...
- mac 系统安装selenium注意事项
mac最新系统:OS X EI Captian python: 本机自带的python2.7. (本来想升级3.5,觉得太复杂,放弃了) pip: https://pypi.python.org/py ...
- R语言学习笔记2——绘图
R语言提供了非常强大的图形绘制功能.下面来看一个例子: > dose <- c(20, 30, 40, 45, 60)> drugA <- c(16, 20, 27, 40, ...
- 用python实现ping
#!/usr/bin/env python #coding=utf-8 import os import argparse import socket import struct import sel ...
- Git--将服务器代码更新到本地
1. git status(查看本地分支文件信息,确保更新时不产生冲突) 2. git checkout -- [file name] (若文件有修改,可以还原到最初状态; 若文件需要更新到服务器上, ...
- android 下使用Direct Texture
要使用Direct Texture,需要有一份android系统的源码 部分C++代码如下: #include <stdio.h> #include <stdlib.h> #i ...
- woff字体找不到导致的404错误
在iis中添加mime类型: .woff application/x-font-woff .woff2 application/x-font-woff
- CSS3与页面布局学习总结(四)——页面布局的多种方法
一.负边距与浮动布局 1.1.负边距 所谓的负边距就是margin取负值的情况,如margin:-100px,margin:-100%.当一个元素与另一个元素margin取负值时将拉近距离.常见的 ...
- HTML&CSS 问题
1.子div使用浮动,父div高度自适应(个人感觉好用) 方法: css: <style> .clear{ clear:both} </style> html:在父div关闭之 ...