2009-12-19 13:55:11 转成 4B 2C 6A BF
   4B 2C CD 2F 转成 2009-12-19 20:55:11就是互转.

解决方案 »

  1.   

    时间是8个字节long类型
    使用TICK属性。
    然后把这个TICK按照十六进制格式输出就可以了。
      

  2.   

    byte[] b = { 0x4b, 0x2c, 0xcd, 0x2f, 0, 0, 0, 0 };
    DateTime dt = DateTime.FromBinary(BitConverter.ToInt64(b, 0));
      

  3.   

    public static string ConvertToHex(struing str, bool reverse)
    {
     byte[] arrByte=System.Text.Encoding.Default.GetBytes(str);
        StringBuilder sb = new StringBuilder();
        if (reverse)
            Array.Reverse(arrByte);
        foreach (byte b in arrByte)
            sb.AppendFormat("{0:x2}", b);
        return sb.ToString();
    }
      

  4.   


                DateTime DT = DateTime.Parse("2009-12-19 13:55:11");
                double D = DT.ToOADate();
                Byte[] Bytes = BitConverter.GetBytes(D);
                String S = BitConverter.ToString(Bytes);
                MessageBox.Show(S); //2D-E3-43-8F-D2-9C-E3-40
      

  5.   


     DateTime t = DateTime.Parse("1970-1-1");
     DateTime t1 = t.AddSeconds(0x4B2CCD2F).ToLocalTime();
     DateTime t2=t.AddSeconds(0x4B2C6ABF ).ToLocalTime();
     double t3 = (DateTime.Now - t).TotalSeconds;
      

  6.   


    怎么转回 时间?
    Convert.ToString((int)t3, 16)这样好像错了
      

  7.   

     那吧时间转换成string呢?
      

  8.   


    Byte[] Bytes = BitConverter.GetBytes(t3);
      

  9.   

    DateTime t= DateTime.Parse("1970-1-1"); 
    DateTime t1= t.AddSeconds(0x4B2CCD2F).ToLocalTime(); 
    DateTime t2=t.AddSeconds(0x4B2C6ABF ).ToLocalTime();
    //double t3= (DateTime.Now- t).TotalSeconds; 
    double t3= (t1- t).TotalSeconds; Byte[] Bytes = BitConverter.GetBytes(t3); 
    0000C06B4FCBD241还是不会.........  
      

  10.   


    long t4 = (long)t3;
    byte[] bs = BitConverter.GetBytes(t4);
      

  11.   

    byte[] bs = BitConverter.GetBytes(System.Net.IPAddress.NetworkToHostOrder(t4));
      

  12.   

    唉DateTime t = DateTime.Parse("1970-1-1");
                DateTime t1 = t.AddSeconds(0x4B2CCD2F).ToLocalTime();
                DateTime t2 = t.AddSeconds(0x4B2C6ABF).ToLocalTime();            double t3 = (t1 - t).TotalSeconds;
                long t4 = (long)t3;
                byte[] bs = BitConverter.GetBytes(System.Net.IPAddress.NetworkToHostOrder(t4));
                string s1 = BitConverter.ToString(bs);
      

  13.   

    这是UNIX时间戳...答案已经有了...
      

  14.   


    得出的是
    00-00-00-00-4B-2D-3D-AF我想要的是原来这个啊
    0x4B2CCD2F
      

  15.   


    DateTime dt = DateTime.Parse("2009-12-19 13:55:11");
    string s = ((dt.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString("x");
    Console.WriteLine(s);
    //out:4b2c6abf
      

  16.   

    using System;
    using System.Collections.Generic;
    using System.Text;namespace WWFramework.DateTimes
    {
        /// <summary>
        /// 时间相关函数
        /// </summary>
        public static class Function
        {
            /// <summary>
            /// 将Unix时间戳转换为DateTime类型时间
            /// </summary>
            /// <param name="d">double 型数字</param>
            /// <returns>DateTime</returns>
            public static System.DateTime ConvertIntDateTime(double d)
            {
                 System.DateTime time = System.DateTime.MinValue;
                 System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
                 time = startTime.AddSeconds(d);
                return time;
             }        /// <summary>
            /// 将c# DateTime时间格式转换为Unix时间戳格式
            /// </summary>
            /// <param name="time">时间</param>
            /// <returns>double</returns>
            public static double ConvertDateTimeInt(System.DateTime time)
            {
                double intResult = 0;
                 System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
                 intResult = (time - startTime).TotalSeconds;
                return intResult;
             }
         }
    }
      

  17.   

    谢谢楼上的各位
    由其是 soaringbird  呵呵
    真的非常感谢
    原来那个时间 是 1970 1 1 8  得加个小时