如题,因为同事负责的一个模块是C++做的,发送给我的时间是systemtime,该怎么转换成DateTime呢(我使用C#)

解决方案 »

  1.   

    补充:套接字发送,发送端序列化,我接到后反序列化;但C#。NET能识别C++里的systemtime吗?还是贴点代码吧        //序列化
            public byte[] Serialize(object obj)
            {
                BinaryFormatter binaryF = new BinaryFormatter();
                MemoryStream ms = new MemoryStream(1024 * 10);
                binaryF.Serialize(ms, obj);
                ms.Seek(0, SeekOrigin.Begin);
                byte[] buffer = new byte[(int)ms.Length];
                ms.Read(buffer, 0, buffer.Length);
                ms.Close();
                return buffer;
            }        //反序列化
            public object Deserialize(byte[] buffer)
            {
                BinaryFormatter binaryF = new BinaryFormatter();
                MemoryStream ms = new MemoryStream(buffer, 0, buffer.Length, false);
                object obj = binaryF.Deserialize(ms);
                ms.Close();
                return obj;
            }   //数据结构
        public struct AlertInfo  
        {
        public char[] CallerCode; //主叫号码 32
        public char[] CalleeCode; //被叫号码         32
        char[] RecvDtmf; //所有接收的报代码 256
        
            //下面的数据需要接中心端返回
        public char[] UserCode; //用户编码     16
        public char[] EventCode; //事件编码         16
        public char[] RegionCode; //地区编码     16
        public char[] EventType; //事件类型      8
        DateTime PickTime; //报警时间SYSTEMTIME PickTime;        /// <summary>
            /// 构造函数,参数随便一个int就可以
            /// </summary>
            /// <param name="ConstructType">随便的整数</param>
            public AlertInfo(int ConstructType)
            {
                CallerCode = new char[32];
                CalleeCode = new char[32];
                RecvDtmf = new char[256];            UserCode = new char[16];
                EventCode = new char[16];
                RegionCode = new char[16];
                EventType = new char[8];
                PickTime = new DateTime();
                
            }
        };
      

  2.   

    SystemTime本身就是一个记录月日年、时分秒和毫秒的结构
    using System.Runtime.InteropServices;[StructLayout(LayoutKind.Sequential)]
    public struct SystemTime
    {
        public ushort wYear;
        public ushort wMonth;
        public ushort wDayOfWeek;
        public ushort wDay;
        public ushort wHour;
        public ushort wMinute;
        public ushort wSecond;
        public ushort wMilliseconds;
    }[DllImport("kernel32.dll")]
    public static extern void GetLocalTime(ref SystemTime lpSystemTime);private void button1_Click(object sender, EventArgs e)
    {
        SystemTime vSystemTime = new SystemTime();
        GetLocalTime(ref vSystemTime);
        DateTime vDateTime = new DateTime(
            vSystemTime.wYear, vSystemTime.wMonth, vSystemTime.wDay, // 月日年
            vSystemTime.wHour, vSystemTime.wMinute, vSystemTime.wSecond, // 时分秒
            vSystemTime.wMilliseconds); // 毫秒
        Text = vDateTime.ToString();
    }
      

  3.   

    C++的system.datetime 类型和 C#的system.datetime 表示的时间格式是一样的
    DateTime dt =System.DateTime.now;
    如果要(2007-11-28)这样的格式 
    string str=dt.Date.ToString("yyyy-MM-dd");
      

  4.   

    static double seed = (double)time(NULL);
    是什么意思?怎么用的?我现在要c#里面实现,怎么样转化呢?谢谢指教!