在此代码中,我将数据保存在文件中,Examdate
,Examtime
和DOB
保存的位置为ex:03:15 PM,我希望它们为1515(带有也是秒。我不知道该怎么办?
Private Sub HL_Click(sender As Object, e As EventArgs) Handles HL.Click
Dim file As System.IO.StreamWriter
Dim fileDateTime As String = DateTime.Now.ToString("yyyyMMdd") & "_" & DateTime.Now.ToString("HHmmss")
file = My.Computer.FileSystem.OpenTextFileWriter(fileDateTime, True)
file.WriteLine("MSH|^~\&|||||" & TxtExamtime.Text & "||ORM^O01||P|2.3.1")
file.WriteLine("PID|||" & TxtId.Text & "||" & TxtFamilyname.Text & "^" & TxtGivenname.Text & "||" & TxtDob.Text & "||" & TxtGender.Text & "|||" & TxtStreet.Text & " " & TxtHouse.Text & "^^" & TxtCity.Text & "^^" & TxtPostcode.Text)
file.WriteLine("PV1||O|||||||||||||||||" & TxtId.Text & "|||||||||||||||||||||||||" & TxtExamdate.Text)
file.WriteLine("ORC|NW|" & TxtId.Text & "|||||^^^" & TxtExamdate.Text & "||" & TxtExamdate.Text)
file.WriteLine("OBR||" & TxtExamdate.Text & TxtExamdate.Text & "||CT|||" & TxtExamtime.Text & "|" & TxtExamtime.Text)
file.WriteLine()
file.Close()
MessageBox.Show("Textsaved to " & fileDateTime)
End Sub
答案 0 :(得分:1)
由于看起来您正在处理文本值而不是日期,因此您必须将其转换为DateTime
变量,然后再返回所需的格式。例如:
DateTime.Parse(txtExamtime.Text).ToString("HHmmss")