使用 vb.net 为没有分隔符的日期添加分隔符

Adding separators for date which are without separators using vb.net

我有一个格式为“13092017”的日期,我必须向其中添加分隔符“-”并使用 vb.net 在文本框中显示。

    Private Sub SettlementDetailUpload_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Try

        Dim s1 As String = "13092017"


    Catch ex As Exception
    End Try
End Sub

你可以这样做:

Private Sub SettlementDetailUpload_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Try
        Dim s1 As String = "13092017"
        Dim DayStr, MonthStr, YearStr, FinalDate As String

        DayStr = s1.Remove(2)
        MonthStr = s1.Substring(2, 2) 'The first '2' is where to start cutting and the 2nd '2' is how much you need to cutm which is 2 in this case.
        YearStr = s1.Substring(4)

        FinalDate = DayStr & "-" & MonthStr & "-" & YearStr
        Msgbox(FinalDate)
    Catch : End Try
End Sub

希望有用:)