如何将DD/MM/YYYY (时间不在此处)日期格式转换为dd-MM-yyyy格式。请确保我只有DD/MM/YYYY,它不包括时间,我想将其转换为dd-MM-YYYY格式。请帮帮忙。
发布于 2011-01-11 13:17:38
用C#语言编写的代码。
string from = "17/5/1983";
DateTime dt = DateTime.ParseExact(from, "d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture).Date;
string to = dt.ToString("dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);输出: 17-05-1983
返回预期的DateTime格式的字符串。我试过了,它运行良好。
尝试以下代码,将日期时间格式转换为"DD-MM-YYYY“格式
以下是有关此主题的MSDN文档:自定义日期和时间格式字符串
请标记为答案。
Abhishek
发布于 2011-01-11 13:18:41
您可以在.NET中使用DateTime -C#中的example:
DateTime inputTime = DateTime.ParseExact("11/01/2011",
"d/M/yyyy",
CultureInfo.InvariantCulture);
string outputTime = inputTime.ToString("dd-MM-yyyy");发布于 2011-01-11 16:50:41
C# language中的
下面的代码将excel导入到数据集中。
/************************** Code **********************************/
String strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Book2.xls;" +
"Extended Properties=Excel 8.0;";
DataSet ds = new DataSet();
//You must use the $ after the object
//you reference in the spreadsheet
OleDbDataAdapter da = new OleDbDataAdapter
("SELECT * FROM [Sheet1$]", strConn);
//da.TableMappings.Add("Table", "ExcelTest");
da.Fill(ds);
DataTable _Dt = ds.Tables[0];
foreach (DataRow row in _Dt.Rows)
{ int outint=0;
if(Int32.TryParse(Convert.ToString(row[0]),out outint))
{
// write your code here
// if condition is true then it validate the integer otherwise it is not valid number format
}
}
/************************************************************/试试看。如果有任何问题,让你知道。
谢谢Abhishek
https://stackoverflow.com/questions/4654425
复制相似问题