WYB
2021-03-22 91b8cdad021ab052e4991f3d41834a6f0ddc36b8
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace JiepeiWMS.Extends
{
    /// <summary>
    /// 数值扩展
    /// </summary>
    public static class ExtNumber
    {
        /// <summary>
        /// 时间戳(秒级)转换日期
        /// </summary>
        /// <param name="Value">数值</param>
        /// <param name="Hour">正8区</param>
        /// <returns></returns>
        public static DateTime _ToTimestampTime(this Int64 Value, int Hour = 8)
        {
            var dt = new DateTime(1970, 1, 1);
            var val = Value * 10000000;
            var tm = dt.AddTicks(val).AddHours(Hour);
            return tm;
        }
        /// <summary>
        /// 时间戳(毫秒级)转换日期
        /// </summary>
        /// <param name="Value">数值</param>
        /// <param name="Hour">正8区</param>
        /// <returns></returns>
        public static DateTime _ToTimestampTimeByMs(this Int64 Value, int Hour = 8)
        {
            var val = Value * 10000;
            var tm = new DateTime(val).AddHours(Hour);
            return tm;
        }
        /// <summary>
        /// 转换成字节
        /// </summary>
        /// <param name="Value">数值</param>
        /// <returns>字节数组</returns>
        public static byte[] _ToBytes(this ulong Value)
        {
            byte[] bytes = new byte[8];
            bytes[7] = (byte)(Value & 0xFF);
            bytes[6] = (byte)(Value >> 8 & 0xFF);
            bytes[5] = (byte)(Value >> 16 & 0xFF);
            bytes[4] = (byte)(Value >> 24 & 0xFF);
            bytes[3] = (byte)(Value >> 32 & 0xFF);
            bytes[2] = (byte)(Value >> 40 & 0xFF);
            bytes[1] = (byte)(Value >> 48 & 0xFF);
            bytes[0] = (byte)(Value >> 56 & 0xFF);
            return bytes;
        }
 
    }
 
}