当前位置:首页 > 通信资讯 > 正文

php时间戳转换成时间(时间戳转换为分钟)

?
1 2 3 4 5 6 7 8 9 10 11 12 13 /** 获取当前时间戳,精确到毫秒 */ function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } /** 格式化时间戳,精确到毫秒,x代表毫秒 */ function microtime_format($tag, $time) { list($usec, $sec) = explode(".", $time); $date = date($tag,$usec); return str_replace('x', $sec, $date); }

使用方法:

1. 获取当前时间戳(精确到毫秒):microtime_float()

2. 时间戳转换时间:microtime_format('Y年m月d日 H时i分s秒 x毫秒', 1270626578

.net 时间戳互相转换(精确到毫秒)

这里记录一个时间戳的互相转换方法,网上都找了,基本都没有精确到毫秒,我的这个基本可以满足精确到毫秒的级别,代码如下:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 /// <summary> /// Unix时间戳转换为DateTime /// </summary> private DateTime ConvertToDateTime(string timestamp) { System.DateTime time = System.DateTime.MinValue; //精确到毫秒 //时间戳转成时间 DateTime start = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(, , )); try { time = timestamp.Length == ? start.AddSeconds(long.Parse(timestamp)) : start.AddMilliseconds(long.Parse(timestamp)); } catch (Exception ex) { return start;//转换失败 } return time; } /// <summary> /// DateTime转换为Unix时间戳 /// </summary> /// <param name="time"></param> /// <returns></returns> private string ConvertTimestamp(DateTime time) { double intResult = ; System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(, , )); intResult = (time - startTime).TotalMilliseconds; return Math.Round(intResult,).ToString(); }
如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。