字符串未被识别为有效日期时间:System.FormatExeception [英] String was not recognized as a Valid Date Time : System.FormatExeception

查看:107
本文介绍了字符串未被识别为有效日期时间:System.FormatExeception的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我需要帮助来解决这个问题:



以下是我的代码:



Hi Friends,

I need a help to solve this issue:

Below is my Code:

Dim Time As DateTime = DateTime.ParseExact(Value, "dd-MMM-yyyy", CultureInfo.InvariantCulture)
Dim TimeString As String = Time.ToString("dd-MMM-yyyy")
TextBox.Text = TimeString





值是字符串,其值为:''08/12/20''即' 'dd / MM / yyyy''。

我的实际需要是将这些数据从DB转换为''08 -DEC-2012'',即'dd-MMM-yyyy'格式。



但由于以下错误,我很震惊:



String未被识别为有效的DateTime。 ---> System.FormatException:String未被识别为有效的DateTime。





请帮我解决这个问题。

提前致谢!!!



Value is the String which is having Value as : ''08/12/2012'' i.e in ''dd/MM/yyyy''.
And my actual need is to convert this data from DB to ''08-DEC-2012'' i.e in ''dd-MMM-yyyy'' format.

But i am struck to get that due to the following error :

String was not recognized as a valid DateTime. ---> System.FormatException: String was not recognized as a valid DateTime.


Please help me to sort this problem.
Thanks in advance !!!

推荐答案

您的ParseExact格式错误:

Your ParseExact format is wrong:
Dim Time As DateTime = DateTime.ParseExact(Value, "dd-MMM-yyyy", CultureInfo.InvariantCulture)

预计日期为2012年1月25日

你想要

Expects the date as "25-Jan-2012"
You want

Dim Time As DateTime = DateTime.ParseExact(Value, "dd/MM/yyyy", CultureInfo.InvariantCulture)

哪个期望25/01/2012

Which expects "25/01/2012"


这篇关于字符串未被识别为有效日期时间:System.FormatExeception的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆