C# 生成时间戳

  1. http://novell.me/master-diary/2014-08-02/csharp-generate-timestamp.html
  2. ///
  3. /// 获取当前时间戳
  4. ///
  5. /// 【C# 生成时间戳】为真时获取10位时间戳,为假时获取13位时间戳.
  6. ///
  7. public static string GetTimeStamp(bool bflag = true)
  8. {
  9. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  10. string ret = string.Empty;
  11. if (bflag)
  12. ret = Convert.ToInt64(ts.TotalSeconds).ToString();
  13. else
  14. ret = Convert.ToInt64(ts.TotalMilliseconds).ToString();
  15. return ret;
  16. }

    推荐阅读