如何在将文件保存到文件中时更改日期和时间格式 [英] How to change date and time format while saving it in file
本文介绍了如何在将文件保存到文件中时更改日期和时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#我在第二行代码中 FormatException未处理时收到错误
这是我的代码:
私有 Sub HL_Click(发件人 As 对象,e As EventArgs)句柄 HL。点击
TxtDob.Text = 日期 .Now.ToString( ddMMyyyy)
Dim 文件作为系统.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.WriteL ine()
file.Close()
MessageBox.Show( Textsaved到& fileDateTime)
结束 Sub
解决方案
正如评论中所讨论的,您可以使用以下代码:
TxtDob.Format = DateTimePickerFormat .Custom
TxtDob.CustomFormat = ddMMyyyy
# Am getting an error as FormatException was unhandled in the second line of code
here is my code:
Private Sub HL_Click(sender As Object, e As EventArgs) Handles HL.Click
TxtDob.Text = Date.Now.ToString("ddMMyyyy")
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
解决方案
As discussed in the comments, you were able to get it to work with the following code:
TxtDob.Format = DateTimePickerFormat.Custom TxtDob.CustomFormat = "ddMMyyyy"
这篇关于如何在将文件保存到文件中时更改日期和时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文