UTC时间,13位时间毫秒数,4位随机数,13位的时间戳,MAC地址

编程入门 行业动态 更新时间:2024-10-08 12:38:53

UTC<a href=https://www.elefans.com/category/jswz/34/1771441.html style=时间,13位时间毫秒数,4位随机数,13位的时间戳,MAC地址"/>

UTC时间,13位时间毫秒数,4位随机数,13位的时间戳,MAC地址

string timestamp = "";
//使用UTC时间,ISO8601格式为"yyyy-MM-ddTHH:mm:ss.sss+08:00"
DateTime dt = DateTime.Now;
timestamp = dt.ToString("yyyy-MM-ddTHH:mm:ss.sss+08:00");

//使用13位时间毫秒数 + 4位随机数
System.Random Random = new System.Random();
int Result = Random.Next(1000, 9999);
string auth_Nonce = GetTimeStamp() + Result.ToString();

//获得13位的时间戳
System.DateTime time = System.DateTime.Now; 
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
long ts = (time.Ticks - startTime.Ticks) / 10000;   //除10000调整为13位       
return ts.ToString();

//返回计算机MAC地址
string physicalAddress = ""; 

try {
    InetAddress inetAddress = InetAddress.getLocalHost();
    /**
     * 获取电脑网卡的AMC地址
     * 返回包含硬件地址的 byte 数组;如果地址不存在或不可访问,则返回 null
     * 如果电脑因为网卡被禁用,则这里获取会返回 null
     */
    byte[] mac = NetworkInterface.getByInetAddress(inetAddress).getHardwareAddress();
    if (mac == null) {
        return null;
    }
    StringBuffer stringBuffer = new StringBuffer("");
    for (int i = 0; i < mac.length; i++) {
        if (i != 0) {
            stringBuffer.append("-");
        }
        /**
         * 转换mac的字节数组
         */
        int temp = mac[i] & 0xff;
        String str = Integer.toHexString(temp);
        if (str.length() == 1) {
            stringBuffer.append("0" + str);
        } else {
            stringBuffer.append(str);
        }
    }
    physicalAddress = stringBuffer.toString().toUpperCase();
} catch (SocketException e) {
    e.printStackTrace();
} catch (UnknownHostException e) {
    e.printStackTrace();

return physicalAddress;

更多推荐

UTC时间,13位时间毫秒数,4位随机数,13位的时间戳,MAC地址

本文发布于:2024-02-19 16:33:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1764901.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间   随机数   地址   UTC   MAC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!