2015-05-26 74 views
0

在此代碼中,將數據保存在文件中,並且其中的Examdate,ExamtimeDOB保存爲例如:03:15 PM,我希望它們爲1515 (也有秒)。我不知道該怎麼辦?如何在文件中將日期和時間保存爲yyyymmdd&hhmmss

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

你有你的文本框爲DateTime轉換,如果你想創業做任何操作。 –

回答

1

因爲它看起來像你正在處理一個文本值,而不是一個日期,你必須將它轉換爲DateTime變量,然後返回到你想要的格式。例如:

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

相關問題