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

时间:2017-09-13 09:18:24

标签: datetime vb.net-2010

我的日期格式为&#;; 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

1 个答案:

答案 0 :(得分:0)

你可以这样做:

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

希望它有用:)