欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

時(shí)間戳與時(shí)間相互轉(zhuǎn)換(php .net精確到毫秒)

 更新時(shí)間:2015年09月15日 11:50:13   投稿:mrr  
本文給大家分享的時(shí)間戳與時(shí)間相互轉(zhuǎn)換(php .net精確到毫秒) ,感興趣的朋友一起學(xué)習(xí)吧
/** 獲取當(dāng)前時(shí)間戳,精確到毫秒 */
function microtime_float()
{
  list($usec, $sec) = explode(" ", microtime());
  return ((float)$usec + (float)$sec);
}
/** 格式化時(shí)間戳,精確到毫秒,x代表毫秒 */
function microtime_format($tag, $time)
{
  list($usec, $sec) = explode(".", $time);
  $date = date($tag,$usec);
  return str_replace('x', $sec, $date);
}

使用方法:

1. 獲取當(dāng)前時(shí)間戳(精確到毫秒):microtime_float()

2. 時(shí)間戳轉(zhuǎn)換時(shí)間:microtime_format('Y年m月d日 H時(shí)i分s秒 x毫秒', 1270626578

.net 時(shí)間戳互相轉(zhuǎn)換(精確到毫秒)

這里記錄一個(gè)時(shí)間戳的互相轉(zhuǎn)換方法,網(wǎng)上都找了,基本都沒(méi)有精確到毫秒,我的這個(gè)基本可以滿足精確到毫秒的級(jí)別,代碼如下:

 

 /// <summary>
     /// Unix時(shí)間戳轉(zhuǎn)換為DateTime
     /// </summary>
     private DateTime ConvertToDateTime(string timestamp)
     {
       System.DateTime time = System.DateTime.MinValue;
       //精確到毫秒
       //時(shí)間戳轉(zhuǎn)成時(shí)間
       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;//轉(zhuǎn)換失敗
       }
       return time;
     }
     /// <summary>
     /// DateTime轉(zhuǎn)換為Unix時(shí)間戳
     /// </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();
     }

相關(guān)文章

最新評(píng)論