【问题标题】:Transform date represented as String to Date in Visual Basic在 Visual Basic 中将表示为字符串的日期转换为日期
【发布时间】:2009-11-20 16:04:18
【问题描述】:

我正在使用SSIS,我需要转换日期。 如何在 VB.NET 中将字符串格式的日期(例如 1980 年 9 月 14 日)转换为相同但日期格式?

我希望将日期时间格式插入 SQL 数据库。

【问题讨论】:

    标签: vb.net ssis


    【解决方案1】:

    在VB.NET:

    ' Assume the current culture is en-US. 
    ' The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.
    Dim myDateTimeValue As String = "2/16/1992 12:15:12"  
    Dim myDateTime As DateTime = DateTime.Parse(myDateTimeValue)
    
    ' Reverse month and day to conform to a different culture.
    ' The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.
    Dim cultureGB = New CultureInfo("en-GB", True)
    Dim myDateTimeValue As String = "16/2/1992 12:15:12"  
    Dim myDateTime As DateTime = DateTime.Parse(myDateTimeValue, cultureGB)
    
    ' Dsiplay the date in DD/MM/YYYY format
    Debug.Print Format(myDateTime ,"dd/MM/yyyy")
    

    参考:http://msdn.microsoft.com/en-us/library/1k1skd40(VS.80).aspx

    在VB6:

    dim dt as date
    dim s as string
    s="10/09/2009"
    dt = cdate(s)
    

    【讨论】:

    • 谢谢!如果我的日期是欧洲格式? dd/mm/aaaa
    • 但是如果我尝试打印 myDateTime 是美国格式...我如何以欧洲格式打印(并插入数据库)?谢谢
    猜你喜欢
    • 1970-01-01
    • 2017-01-18
    • 2011-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多