我有一个从文本文件返回的日期时间,它是一个字符串,格式如下:
周六15-07-2016 00:55:54
如图所示
"dddd dd-MM-yyyy HH:mm:ss“
我试图使用DateTime将其转换为DateTime.ParseExact格式,我的代码如下:
CultureInfo provider = CultureInfo.InvariantCulture;
string lastLine = File.ReadLines("logon.txt").Last(); //the date string is in the logon.txt
Da
犯错误,如:
System.FormatException类型的未处理异常出现在mscorlib.dll附加信息中:字符串不能识别为有效的DateTime。
我正在使用以下代码:
string datetime = DateTime.Parse(encrypt[1]);
或
string datetime = Convert.ToDatetime(encrypt[1]);
加密是一个字符串数组。
在encrypt[1],我是not sure which format will come in string。我追踪到了一些时间-- dd/MM/yyyy,有时MM/dd/yyyy,MM-d
我试图使用以下语句进行简单的解析:
//In actual code the date time value comes from db
var dateTime = new DateTime(2018, 04, 26);
var dtExtact = DateTime.ParseExact(dateTime.ToString(), "dd MMM yyyy HH:mm:ss:fff",null);
当我尝试犯错误时,
System.FormatException:“字符串不能识别为有效的DateTime。”
我确实看了一下示例,但是它没有提供任何关于我的约会时间有什
我有类似于03/10/1999的日期字符串,其中格式是dd/MM/yyyy (pt-BR格式)。
我需要将这个日期转换为类似于SQL格式的yyyy-MM-dd HH:mm:ss.fff。
我尝试使用Parse和ParseExact函数,但到目前为止没有成功。我会让我的结果如下..。
使用解析
var BrazilianDate = "03/10/1999";
var Parse = DateTime.Parse(BrazilianDate, new CultureInfo("pt-BR"));
Console.WriteLine("Parsed dat
我已经寻找了一段时间来寻找这个答案:
我有一个datagridview,它有一个包含日期的单元格,我需要将该单元格中的值设置为可以与我的DateTimePicker匹配的DateTime值
到目前为止,我已经这样做了,但它没有工作,它给了我一个System.FormatException (显然它不能将字符串识别为DateTime,这听起来是对的)
下面是有问题的代码:
int index = ReservationDataGridView.SelectedRows[0].Index;
string date = ReservationDataGridView[0, 1].Value.ToSt
以下代码
var test = "2016-10-26_02-48-17-PM";
var testTime = DateTime.ParseExact(test,
"yyyy-MM-dd_HH-mm-ss-tt",
System.Globalization.CultureInfo.InvariantCulture);
抛出异常;
System.FormatException类型的未处理异常发生在mscorlib.dl
所以我有个日期串和今天的短日期一起来。例如"1-11-2017“
//Here i convert the HttpCookie to a String
string DateView = Convert.ToString(CurrDay.Value);
//Here i convert the String to DateTime
DateTime myDate = DateTime.ParseExact(DateView, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
在运行代
dim dt as string= "03/22/20 20:12:27.320"
Dim tempDate As DateTime = DateTime.ParseExact(dt, "MM/dd/yy hh:mm:ss.fff", CultureInfo.GetCultureInfo("en-US").DateTimeFormat)
这有时会给出错误: System.FormatException:‘字符串未被识别为有效的DateTime。’
为什么?它的格式似乎是正确的。VB.net 4.6.1框架
我是VB.net的新手,所以请耐心点。
我试图从数据文件中解析日期/时间数据:
Dim line As String = " Stime 31/05/2016 08:29:36"
Dim start_time As DateTime = DateTime.ParseExact(line, " Stime dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture)
System.FormatException是未处理的,Message=String不能被识别为有效的DateTime。
Line: "