zoukankan      html  css  js  c++  java
  • 时间戳,产生随机数

    1 static void Main( string[] args )
    2 {
    3     string    s    = getTimestamp();
    4     string    ss    = getNoncestr();
    5     Console.WriteLine( ss );
    6     Console.WriteLine( s );
    7     Console.ReadKey();
    8 }
    /*
     * / <summary>
     * / 生成时间戳
     * / 从 1970 年 1 月 1 日 00:00:00 至今的秒数,即当前的时间,且最终需要转换为字符串形式
     * / </summary>
     * / <returns></returns>
     */
    public string getTimestamp()
    {
        TimeSpan ts = DateTime.UtcNow - new DateTime( 1970, 1, 1, 0, 0, 0, 0 );
        return(Convert.ToInt64( ts.TotalSeconds ).ToString() );
    }
    public static string getNoncestr()
    {
        Random random = new Random();
        return(MD5Util.GetMD5( random.Next( 1000 ).ToString(), "GBK" ) );
    }
    
    
    public class MD5Util
    {
        public MD5Util()
        {
    /*
     *
     * TODO: 在此处添加构造函数逻辑
     *
     */
        }
    
    
    /** 获取大写的MD5签名结果 */
        public static string GetMD5( string encypStr, string charset )
        {
            string                retStr;
            MD5CryptoServiceProvider    m5 = new MD5CryptoServiceProvider();
    
    /* 创建md5对象 */
            byte[]    inputBye;
            byte[]    outputBye;
    
    /* 使用GB2312编码方式把字符串转化为字节数组. */
            try
            {
                inputBye = Encoding.GetEncoding( charset ).GetBytes( encypStr );
            }
            catch ( Exception ex )
            {
                inputBye = Encoding.GetEncoding( "GB2312" ).GetBytes( encypStr );
            }
            outputBye = m5.ComputeHash( inputBye );
    
            retStr    = System.BitConverter.ToString( outputBye );
            retStr    = retStr.Replace( "-", "" ).ToUpper();
            return(retStr);
        }
    }
  • 相关阅读:
    递归和回溯_leetcode-floodfill
    递归和回溯_leetcode131
    递归和回溯_leetcode130
    递归和回溯_leetcode93-经典的回溯题
    递归和回溯_leetcode90
    递归和回溯_leetcode79
    递归和回溯_leetcode78-经典的子集
    知识树杂谈(1)
    Android 设备兼容性(1)
    微信小程序- 生成二维码
  • 原文地址:https://www.cnblogs.com/ZkbFighting/p/7591682.html
Copyright © 2011-2022 走看看