在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
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(1468482273277)); } /// <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(1970, 1, 1)); 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(1970, 1, 1, 0, 0, 0, 0)); //intResult = (time- startTime).TotalMilliseconds; long t = (time.Ticks - startTime.Ticks) / 10000; //除10000调整为13位 return t; } } 其他获取当前时间戳Javatime JavaScriptMath.round(new Date() / 1000) .NET / C#(DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000 PHPtime() MySQLSELECT unix_timestamp(now()) SQL ServerSELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE()) SQLiteSELECT strftime('%s', 'now') PostgreSQLSELECT extract(epoch FROM now()) Python先 import time 然后 time.time() Ruby获取Unix时间戳:Time.now 或 Time.new显示Unix时间戳:Time.now.to_i Perltime SwiftNSDate().timeIntervalSince1970 Objective-C[[NSDate date] timeIntervalSince1970] Erlangcalendar:datetime_to_gregorian_seconds(calendar:universal_time())-719528*24*3600. Goimport ("time") int32(time.Now().Unix()) Unix / Linuxdate +%s VBScript / ASPDateDiff("s", "01/01/1970 00:00:00", Now()) |
请发表评论