FORMAT EXCEPTION未得到处理 [英] FORMAT EXCEPTION was unhandled
本文介绍了FORMAT EXCEPTION未得到处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在MM / dd / yyyy MM点击按钮时更改DataGridView中的DATE FORMAT:hh:tt to dd / MM / yyyy hh:MM:tt并且它在这一行上给出错误
Hi,
I have a requirement to change the DATE FORMAT in the DataGridView on a button click from MM/dd/yyyy MM:hh:tt to dd/MM/yyyy hh:MM:tt and it's giving error on this line
String.Format("{dd/MM/yyyy hh:MM:tt}", data);
以下是代码:
Below is the code:
Date_Format df = new Date_Format();
df.cmbColumns.DataSource = cmbList;
df.ShowDialog();
string data = "";
foreach (DataGridViewRow row in dataGridView1.Rows)
{
data = Convert.ToString(row.Cells["Sent Date"].Value);
String.Format("{dd/MM/yyyy hh:MM:tt}", data);
}
推荐答案
嗯...
String .Format使用'{'和'}'来表示替换参数 - 但参数由数字索引指示,而不是格式字符串,并希望它们匹配。
所以:
Um...
String.Format uses '{' and '}' to indicate parameters for substitution - but the parameters are indicated by a numeric index rather than being a format string and hoping they match up.
So:
String.Format("{0}", data);
有效,但你尝试的不是。
但是这里没有其他许多问题...
尝试这个而不是string.Format:
Is valid, but what you tried is not.
But there are no many other problems here...
Try this instead of string.Format:
DateTime date = (DateTime) (row.Cells["Sent Date"].Value);
string formattedDate = date.ToString("dd/MM/yyyy hh:mm:tt");
这篇关于FORMAT EXCEPTION未得到处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文