English 中文(简体)
显示日期改为时间格式
原标题:Converting Date string to DateTime Format vb.net

我有这个例子,它给我以例外:“从X射线到现在都是无效的”。

这里是我验证日期的方法。

例: “27/03/1985”

Public Function validateDateColumn(ByRef FieldName As String) As Boolean

    Try
        If IsDate(FieldName) Then
            Dim actualDate As DateTime = CDate(FieldName)
            Dim DtLicExp As DateTime = CDate(actualDate.ToString("d", Thread.CurrentThread.CurrentCulture))
            FieldName = DtLicExp.ToString("MM/dd/yyyy")
            Return True
        End If
    Catch ex As Exception
         FieldName &= "Format must be MM/dd/yyyy"
        Return False
    End Try

End Function

任何认可这一日期的想法都是迄今为止的囚犯。

我将这一日期改为“27/03/1985”。

I m 采用p.net和vb.net。

最佳回答
问题回答

这一执行将按要求,规定格式<编码>d/MM/yyyyyy的日期,并更新MM/dd/yyyyyyy。 <代码>Datetime.TryParseExact 允许你具体说明你需要的日期。

Public Function validateDateColumn(ByRef FieldName As String) As Boolean

  validateDateColumn = False

  Dim dateValue As DateTime

  if DateTime.TryParseExact(FieldName, _
      "dd/MM/yyyy", CultureInfo.InvariantCulture, _
      DateTimeStyles.None, dateValue) Then

      validateDateColumn = True
      FieldName = dateValue.ToString("MM/dd/yyyy")
  End If

End Function

您可尝试<代码>TryParse方法。

Dim myDateString as String = "7/7/2010"
Dim myDate as DateTime
Dim isDate As Boolean = DateTime.TryParse(myDateString, myDate)

If isDate Then
      Yay I m a real date
End If




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签