【C#】如何获取Smartphone的当前时间?(精确到ms,因为要测定网络延时)

AvalonFX 2007-09-19 10:43:14
谢谢!!
...全文
279 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
gucheng2008 2007-11-19
  • 打赏
  • 举报
回复
要想获取毫秒值,必须用API函数,不过要有相应的硬件支持才行。幸好在模拟器和我的PPC上都支持。
[DllImport( "\\windows\\coredll.dll ", EntryPoint = "GetTickCount ")]
public static extern int GetTickCount();
用这个试试吧~~
AvalonFX 2007-10-12
  • 打赏
  • 举报
回复
试过,感觉也不对。
以下面代码为例,TickCount统计的差值 和 CurrentTime不一样。
而且后者更合理。


/***************************************************
* TickCount感觉也不对
****************************************************/
private void menuItem2_Click(object sender, EventArgs e)
{
System.DateTime currentTime = System.DateTime.Now;
String str;
str = "";
str += currentTime.ToString() + "\r\n"
+ System.Environment.TickCount + "\r\n";

int y = 0;
for (int i = 0; i < 100000; i++)
{
y += i;
}
currentTime = System.DateTime.Now;
str += currentTime.ToString() + "\r\n"
+ System.Environment.TickCount + "\r\n";

MessageBox.Show(str);
}
AvalonFX 2007-10-10
  • 打赏
  • 举报
回复
无比的感谢。。
I can't thank you more
徐蕴 2007-10-10
  • 打赏
  • 举报
回复
试过GetTickCount吗?开机到现在的时间。
gucheng2008 2007-10-08
  • 打赏
  • 举报
回复
刚才式了一下,还真的为0,特纳闷,PC机上就可以得到~~~再给你找下这方面的资料吧,有信息了通知你吧~~
AvalonFX 2007-10-07
  • 打赏
  • 举报
回复
to gucheng2008 :试过了,还是不行。
这个方法在Microsoft提供的.net CF里面有讲述,但未说明毫秒是否可用。测试过,不可用,wMilliseconds始终为0。

可能是没有办法了,等几天再没有答案就结贴把
AvalonFX 2007-09-30
  • 打赏
  • 举报
回复
万分谢谢!
gucheng2008 2007-09-24
  • 打赏
  • 举报
回复
这些api函数一般都在coreldll.dll文件里,这个就相当于windows下班的kernel32.dll
[DllImport("coredll.dll", SetLastError = true)]
public static extern int GetLocalTime(ref SystemTime lpSystemTime);

public struct SystemTime
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}

试试这个吧

AvalonFX 2007-09-22
  • 打赏
  • 举报
回复

如果你能调API的话,可以用
void GetLocalTime(
LPSYSTEMTIME lpSystemTime
);
-------------
谢谢,其实我就是想用这个API,但是不知道怎么用
因为Smartphone不带System32.dll
2021‘someday 2007-09-21
  • 打赏
  • 举报
回复
找一下时间方面的,或者减了!
boliang319 2007-09-20
  • 打赏
  • 举报
回复
如果你能调API的话,可以用
void GetLocalTime(
LPSYSTEMTIME lpSystemTime
);
dyw 2007-09-20
  • 打赏
  • 举报
回复
GetTickCount
AvalonFX 2007-09-20
  • 打赏
  • 举报
回复
但是Millisecond 属性在Smartphone(WinCE内核)上不可用。
Mobile_Writer 2007-09-20
  • 打赏
  • 举报
回复
DateTime.Now 就可以呀。前后相减就可知道延时呀。
DateTime.Now.Millisecond 就是 ms

7,660

社区成员

发帖
与我相关
我的任务
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
  • Windows客户端开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧