StringHelper.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace ivf_tl_Entity.ComEntitys
  7. {
  8. public class StringHelper
  9. {
  10. /// <summary>
  11. /// 字节数组转16进制字符串
  12. /// </summary>
  13. /// <param name="bytes"></param>
  14. /// <returns></returns>
  15. public static string ByteToHexStr(byte[] bytes)
  16. {
  17. string returnStr = "";
  18. if (bytes != null)
  19. {
  20. for (int i = 0; i < bytes.Length; i++)
  21. {
  22. returnStr += bytes[i].ToString("X2") + " ";
  23. }
  24. }
  25. return returnStr;
  26. }
  27. /// <summary>
  28. /// 时:分:秒.毫秒
  29. /// </summary>
  30. /// <param name="obj"></param>
  31. /// <returns></returns>
  32. public static string TimeToString(TimeSpan obj)
  33. {
  34. string totalTimeStr = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", obj.Hours, obj.Minutes, obj.Seconds, obj.Milliseconds / 10);
  35. return totalTimeStr;
  36. }
  37. }
  38. }