如何保存DATE&时间作为yyyymmdd& hhmmss在一个文件中

时间:2015-05-26 13:40:30

标签: vb.net date datagridview datepicker hl7

在此代码中,我将数据保存在文件中,ExamdateExamtimeDOB保存的位置为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

1 个答案:

答案 0 :(得分:1)

由于看起来您正在处理文本值而不是日期,因此您必须将其转换为DateTime变量,然后再返回所需的格式。例如:

DateTime.Parse(txtExamtime.Text).ToString("HHmmss")