C#转VB.NET代码,有点问题.

lwy7758 2014-04-01 02:37:39
C#代码:

public static long GetTimestamp(DateTime dateTime)
{
DateTime baseDateTime = DateTime.Parse("1970-1-01 08:00:00.000");
return (long)(dateTime - baseDateTime).TotalMilliseconds;
}

public static uint GetClientID()
{
uint clientid=uint.Parse( new Random(Guid.NewGuid().GetHashCode()).Next(0, 99) + "" + GetTimestamp(DateTime.Now) / 10000000);
return clientid;
}


我转的VB.NET代码:

Public Shared Function GetTimestamp(dateTime1 As DateTime) As Long
Dim baseDateTime As DateTime = DateTime.Parse("1970-1-01 08:00:00.000")
Return CLng((dateTime1 - baseDateTime).TotalMilliseconds)
End Function

Public Shared Function GetClientID() As UInteger
Dim clientid As UInteger
clientid = UInteger.Parse(New Random(Guid.NewGuid().GetHashCode()).[Next](0, 99) & "" & GetTimestamp(DateTime.Now) / 10000000)
Return clientid
End Function


在VS2013里面编译出错,说 输入字符串的格式不正确. 不知道哪里改的不正确.
...全文
104 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
无涯大者 2014-04-01
  • 打赏
  • 举报
回复

Public Shared Function GetTimestamp(dateTime__1 As DateTime) As Long
	Dim baseDateTime As DateTime = DateTime.Parse("1970-1-01 08:00:00.000")
	Return CLng((dateTime__1 - baseDateTime).TotalMilliseconds)
End Function

Public Shared Function GetClientID() As UInteger
	Dim clientid As UInteger = UInteger.Parse(New Random(Guid.NewGuid().GetHashCode()).[Next](0, 99) & "" & GetTimestamp(DateTime.Now) \ 10000000)
	Return clientid
End Function
通过网站转换的,不知道在.net1.1环境下,有误报错!
liuyilin888 2014-04-01
  • 打赏
  • 举报
回复


Public Shared Function GetTimestamp(ByVal dateTime As Date) As Long
Dim baseDateTime As Date = Date.Parse("1970-1-01 08:00:00.000")
Return CLng(Math.Truncate((dateTime.Subtract(baseDateTime)).TotalMilliseconds))
End Function

Public Shared Function GetClientID() As UInteger
Dim clientid As UInteger=UInteger.Parse((New Random(Guid.NewGuid().GetHashCode())).Next(0, 99) + GetTimestamp(Date.Now) \ 10000000)
Return clientid
End Function

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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