我希望将12:00:00 AM
添加到两个日期。
Public Shared Function AddSkill(ByVal empId As Integer, ByVal skillCode As String, ByVal startDate As String, ByVal endDate As String) As String
Dim sDate As DateTime = DateTime.Parse(startDate)
Dim eDate As DateTime = DateTime.Parse(endDate)
Dim empSkill As EmployeeSkills
empSkill = Nothing
If empId > 0 Then
empSkill = EmployeeSkills.GetById(empId)
End If
If empSkill Is Nothing Then
empSkill = New EmployeeSkills
End If
empSkill.SkillID = skillCode
empSkill.EmployeeID = empId
empSkill.StartTime = sDate & sDate.Hour & sDate.Minute & sDate.Second
empSkill.Endtime = eDate & eDate.Hour & eDate.Minute & eDate.Second
empSkill.Save(FSIASecurity.GetUserID)
Return New JavaScriptSerializer().Serialize(empSkill)
End Function
startDate为25/05/2015
endDate可以是任何东西,但我们会说31/05/2016
用于演示目的。
答案 0 :(得分:2)
你应该尝试这样的事情:
'The following example uses the DateTime constructor to instantiate a DateTime value.
Dim date1 As New Date(2015, 5, 25, 12, 0, 0)
点击此处了解详情:https://msdn.microsoft.com/en-us/library/system.datetime%28v=vs.110%29.aspx和https://msdn.microsoft.com/en-us/library/272ba130(v=vs.110).aspx。
答案 1 :(得分:0)
我认为您当前的文化具有日期格式" dd / MM / yyyy HH:mm:ss AM / PM",与加拿大一样。
如果您使用Dim sDate = DateTime.Parse("25/05/2015")
,那么它的时间部分设置为早上00:00:00。那已经是凌晨12点了。如果您使用sDate.ToString()
,则可以检查此项,您将从中获得"25/05/2015 12:00:00 AM"
。
如果您想要一天中的其他时间,只需将自午夜以来的时间添加到sDate
:
下午1:00,这是Dim sDate = DateTime.Parse("25/05/2015") + new TimeSpan(13,0,0)
。