示例#1
0
        private void To()
        {
            //base64
            var character = "ABCDEFG";
            var base64    = "WkhJ5qGG5p6257uE5Lu2";

            Console.WriteLine("base64");
            Console.WriteLine("     ToBase64Encode:{0}", ZConvert.ToBase64Encode(character));
            Console.WriteLine("     ToBase64Decode:{0}", ZConvert.ToBase64Decode(base64));
            //timestamp
            var timestamp = "1609430400";

            Console.WriteLine("timestamp");
            Console.WriteLine("     ToDateTimeFromTimeStamp:{0}", ZConvert.ToDateTimeFromTimeStamp(timestamp));
            Console.WriteLine("     ToTimeStampFromDateTime:{0}", ZConvert.ToTimeStampFromDateTime(DateTime.Now));
            //enum
            Console.WriteLine("enum");
            Console.WriteLine("     ToIntFromEnum:{0}", ZConvert.ToIntFromEnum(TimeStampUnit.Millisecond));
            //ip
            Console.WriteLine("ip");
            Console.WriteLine("     ToIpFromLong:{0}", ZConvert.ToIpFromLong(2130706433));
            Console.WriteLine("     ToLongFromIp:{0}", ZConvert.ToLongFromIp("127.0.0.1"));
            //unicode
            character = "中文";
            var unicode = "\\u8fd9\\u662f\\u0055\\u006e\\u0069\\u0063\\u006f\\u0064\\u0065\\u7f16\\u7801";

            Console.WriteLine("unicode");
            Console.WriteLine("     ToUnicodeEncode:{0}", ZConvert.ToUnicodeEncode(character));
            Console.WriteLine("     ToUnicodeDecode:{0}", ZConvert.ToUnicodeDecode(unicode));
            Console.WriteLine();
            Console.WriteLine();
        }
示例#2
0
        public void Example()
        {
            //将字符串进行base64编码、解码
            var character   = "123456ABCDE";
            var baseString1 = ZConvert.ToBase64Encode(character);
            var baseString2 = ZConvert.ToBase64Decode(baseString1);
            //将时间转为时间戳/将时间戳转为时间
            var timestamp = ZConvert.ToTimeStampFromDateTime(DateTime.Now);
            var datetime  = ZConvert.ToDateTimeFromTimeStamp(timestamp);
            //得到枚举的int32值
            var enumber = ZConvert.ToIntFromEnum(TimeStampUnit.Millisecond);
            //IP转为数字/数字转为IP
            var inumber = ZConvert.ToLongFromIp("127.0.0.1");
            var ip      = ZConvert.ToIpFromLong(inumber);

            //在转换过程中,你并不想在转换失败的时候抛出异常,那么建议你试试TryTo方法
            //将字符串/object转为数字
            var number  = "123456";
            var number1 = ZConvert.TryToInt32(number);  //也可使用:TryToInt16()、TryToInt64()
            var number2 = ZConvert.TryToUInt32(number); //也可使用:TryToUInt16()、TryToUInt64()
            //将时间转为时间戳/将时间戳转为时间
            var timestamp2 = ZConvert.TryToTimeStampFromDateTime(DateTime.Now);
            var datetime2  = ZConvert.TryToDateTimeFromTimeStamp(timestamp);
            //...
        }