C++的systemtime 到 C#的DateTime 如何转换?急等。。。。。。。。。 如题,因为同事负责的一个模块是C++做的,发送给我的时间是systemtime,该怎么转换成DateTime呢(我使用C#) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 补充:套接字发送,发送端序列化,我接到后反序列化;但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(); } }; 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();} C++的system.datetime 类型和 C#的system.datetime 表示的时间格式是一样的DateTime dt =System.DateTime.now;如果要(2007-11-28)这样的格式 string str=dt.Date.ToString("yyyy-MM-dd"); static double seed = (double)time(NULL);是什么意思?怎么用的?我现在要c#里面实现,怎么样转化呢?谢谢指教! 求一条字符串对比语句 sql语句有的前面为什么要加@? 【弱问】初学C#:发邮件的小程序 请高手指点网络编程问题,100分送上 急~~~1920*1080分辨率下怎样才能截取桌面全屏? 怎样在程序中生成一个Excel,并保存到程序运行的目录下。 哪位知道,怎样遍历一个目录得到所有文件名和文件的路径? 银行储蓄系统的设计! 服务器socket接受多个客户端的连接以及接收数据的问题 如何在C#程序中处理除数为0的错误 请问 dataset.xsd 与工具箱中的 DataSet 有什么区别 c#中捕捉ctrl,alt,shift键盘事件
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();
}
};
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();
}
DateTime dt =System.DateTime.now;
如果要(2007-11-28)这样的格式
string str=dt.Date.ToString("yyyy-MM-dd");
是什么意思?怎么用的?我现在要c#里面实现,怎么样转化呢?谢谢指教!