Class property not returning right datetime format
Why doesn´t this property return a datetime formated with the following pattern when using the property in 开发者_JAVA百科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
You might want to switch the return type of UserCreated()
to string since the Get
is actually returning a formatted string and not a DateTime
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
hdnUserLastUpdated.Value = objUser.UserLastUpdated.ToString("yyyy-MM-dd HH:mm:ss.fff")
精彩评论