0

刚开始从 VB6 升级到 VB.Net。

txtFrom.Text = "1/8"
txtFrom.Text = Format(txtFrom.Text, "dd/MM/yyyy")

此代码DD/MM/YYYY在文本框中生成。

我应该怎么做才能生产01/08/13

4

4 回答 4

4

解析日期。重新格式化日期。

Dim d As Date = Date.ParseExact(txtFrom.Text, "d/M", CultureInfo.InvariantCulture)
txtFrom.Text = d.ToString("dd/MM/yy")

自定义日期格式字符串

于 2013-09-29T19:01:47.487 回答
0

格式化函数"dd/MM/yyyy"将格式化日期对象,而不是字符串。您可以使用 CDate 将文本框中的字符串转换为日期:

txtFrom.Text = Format(CDate(txtFrom.Text), "dd/MM/yyyy")

如果日期无效,您可能需要使用IsDateTry-Catch 块。txtFrom.Text

于 2013-09-29T23:15:33.240 回答
0

我应该怎么做才能生产 01/08/13?

dd/MM/yy
于 2013-09-29T19:00:02.570 回答
-2
Dim sFormat As System.Globalization.DateTimeFormatInfo = New System.Globalization.DateTimeFormatInfo()
sFormat.ShortDatePattern = "dd/MM/yyyy"
txtFrom.Text = Format(Convert.ToDateTime(txtFrom.Text+Now.Year.ToString(), sFormat), "dd/MM/yyyy")
于 2013-09-30T02:26:32.617 回答