Asp.Net Unix时间戳和DateTime类型转换
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class weiapi_ceshi : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(ConvertIntDateTime());
}
/// <summary>
/// 将Unix时间戳转换为DateTime类型时间
/// </summary>
/// <param name="d">double 型数字</param>
/// <returns>DateTime</returns>
public static System.DateTime ConvertIntDateTime(double d)
{
System.DateTime time = System.DateTime.MinValue;
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(, , ));
time = startTime.AddMilliseconds(d);
return time;
} /// <summary>
/// 将c# DateTime时间格式转换为Unix时间戳格式,返回格式:1468482273277
/// </summary>
/// <param name="time">时间</param>
/// <returns>long</returns>
public static long ConvertDateTimeInt(System.DateTime time)
{
//double intResult = 0;
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(, , , , , , ));
//intResult = (time- startTime).TotalMilliseconds;
long t = (time.Ticks - startTime.Ticks) / ; //除10000调整为13位
return t;
}
}
其他获取当前时间戳
Java
time
JavaScript
Math.round(new Date() / 1000)
.NET / C#
(DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000
PHP
time()
MySQL
SELECT unix_timestamp(now())
SQL Server
SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE())
SQLite
SELECT strftime('%s', 'now')
PostgreSQL
SELECT extract(epoch FROM now())
Python
先 import time 然后 time.time()
Ruby
获取Unix时间戳:Time.now 或 Time.new显示Unix时间戳:Time.now.to_i
Perl
time
Swift
NSDate().timeIntervalSince1970
Objective-C
[[NSDate date] timeIntervalSince1970]
Erlang
calendar:datetime_to_gregorian_seconds(calendar:universal_time())-719528*24*3600.
Go
import ("time") int32(time.Now().Unix())
Unix / Linux
date +%s
VBScript / ASP
DateDiff("s", "01/01/1970 00:00:00", Now())
Asp.Net Unix时间戳和DateTime类型转换的更多相关文章
- C# Unix时间戳和DateTime类型相互转换
/// <summary> /// 将Unix时间戳转换为DateTime类型时间 /// </summary> /// <param name="d" ...
- Unix时间戳与C# DateTime时间类型互换
Unix时间戳最小单位是秒,开始时间为格林威治标准时间1970-01-01 00:00:00ConvertIntDateTime方法的基本思路是通过获取本地时区表示Unixk开始时间,加上Unix时间 ...
- MSSQL中datetime与unix时间戳互转
//ms sql datetime 转unix时间戳 SELECT DATEDIFF(s, '19700101',GETDATE()) //ms sql unix时间戳 转datetime 涉及到时区 ...
- python datetime和unix时间戳之间相互转换
python datetime和unix时间戳之间相互转换 1.代码: import time import datetime # ...
- c#DateTime与unix时间戳互相转换
public class UnixTimeUtil { /// <summary> /// 将dateTime格式转换为Unix时间戳 /// </summary> /// & ...
- c# dateTime格式转换为Unix时间戳工具类
using System; using System.Collections.Generic; using System.Text; namespace TJCFinanceWriteOff.BizL ...
- [开发笔记]-unix时间戳、GMT时间与datetime类型时间之前的转换
前段时间项目中涉及到了MySql和MsSql数据类型之间的转换,最近又在研究新浪微博的API,涉及到了带有时区的GMT时间类型的转换,所以,特记录于此,以备日后查询. 一:UNIX时间戳与dateti ...
- unix时间戳转换成标准时间(c#)
//---unix时间戳转换成标准时间(c#)---// /* string timeStamp = "1144821796"; DateTime dtSt ...
- UNIX 时间戳 C#
/// 将Unix时间戳转换为DateTime类型时间 /// </summary> /// <param name="d">double 型数字</ ...
随机推荐
- java 把URL中的中文转换成utf-8编码
private static final String QUERY = "餐饮"; String sr = URLEncoder.encode(QUERY); System.out ...
- Window7中Eclipse运行MapReduce程序报错的问题
按照文档:http://www.micmiu.com/bigdata/hadoop/hadoop2x-eclipse-mapreduce-demo/安装配置好Eclipse后,运行WordCount程 ...
- NYOJ-36 最长公共子序列 AC 分类: NYOJ 2014-01-03 20:54 155人阅读 评论(0) 收藏
#include<stdio.h> #include<string.h> #define N 1010 #define max(x,y) x>y?x:y int dp() ...
- NYOJ-469 擅长排列的小明 II AC 分类: NYOJ 2014-01-02 22:19 159人阅读 评论(0) 收藏
最初的第一印象是和组合数一个性质的题目.所以用了回溯法,结果,你懂的... #include<stdio.h> #include<math.h> void dfs(int n, ...
- uva 10994
一开始想法太简单 错了好多遍 #include <cstdio> #include <cstdlib> #include <cmath> #include < ...
- Eclipse对svn操作切换账号或更换svn地址方法
1. 切换账号,主要是删除配置文件达到重新更新svn的时候,弹出框让重新输入新的svn用户名和密码. 1.通过删除SVN客户端的账号配置文件 1)查看你的Eclipse中使用的是什么SVN Int ...
- Ubuntu环境下手动配置ElasticSearch0.90.5
1 下载elasticsearch-0.90.5 2 修改配置(可选) 修改内存:(可选) bin/elasticsearch.in.sh中: ES_MIN_MEM ES_MAX_MEM 修改搜索引擎 ...
- Linux查看机器型号
dmidecode | grep “Product Name”
- codeforces div.1 A
A. Efim and Strange Grade time limit per test 1 second memory limit per test 256 megabytes input sta ...
- LR_问题_控制器不能使用定义的负载生成器
问题描述 在controller 中设置了面向目标的方案后 执行提示 The target you defined cannot be reached.the LoadRunner Controlle ...