类属性未返回正确的日期时间格式
在我的 ASP.NET Webforms 网站的代码隐藏页面中使用该属性时,为什么该属性不返回采用以下模式格式化的日期时间?调试时,我可以看到返回的日期时间值是“2011-02-21 16:13:29.670”,这是正确的。
Public Property UserLastUpdated() As DateTime
Get
Return _userLastUpdated.ToString("yyyy-MM-dd HH:mm:ss.fff")
End Get
Set(ByVal value As DateTime)
_userLastUpdated = value
End Set
End Property
但是当我查看代码隐藏页面中的返回值时,我得到了这个值
objUser.UserLastUpdated = #2/21/2011 4:13:29 PM#
并将返回的属性值分配给.aspx页面中的隐藏字段后,我得到了这个值分配给hiddenfield.value“2011-02-21 16:13 :29"
hdnUserLastUpdated.Value = objUser.UserLastUpdated
Why doesn´t this property return a datetime formated with the following pattern when using the property in the codebehind page in my ASP.NET Webforms website? When debugging i can see that the value the returning datetime is "2011-02-21 16:13:29.670" wich is correct.
Public Property UserLastUpdated() As DateTime
Get
Return _userLastUpdated.ToString("yyyy-MM-dd HH:mm:ss.fff")
End Get
Set(ByVal value As DateTime)
_userLastUpdated = value
End Set
End Property
But when i look at the returned value in the codebehind page i get this value
objUser.UserLastUpdated = #2/21/2011 4:13:29 PM#
And after assigning the returned property value to a hiddenfield in the .aspx page i get this value assign to the hiddenfield.value "2011-02-21 16:13:29"
hdnUserLastUpdated.Value = objUser.UserLastUpdated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能希望将
UserCreated()
的返回类型切换为字符串,因为Get
实际上返回的是格式化字符串,而不是DateTime
实例,或者您可以将其保留为 DateTime 类型,而不在 getter 中进行格式化。您可以在将其分配给隐藏字段值时进行格式化You might want to switch the return type of
UserCreated()
to string since theGet
is actually returning a formatted string and not aDateTime
instance or you could keep it as a DateTime type and not do the formatting in the getter. You could do the formatting when you are assigning it to the hidden field value