我在 asp.net c# 中的日期转换遇到问题。我的 GeneralMethods 类中有以下方法
public DateTime mySqlDateFormate(string dateString, string format="g")
{
dateString = isOk(dateString) ? dateString : DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day;
CultureInfo provider = CultureInfo.InvariantCulture;
// Parse date-only value with invariant culture.
try
{
result = DateTime.ParseExact(dateString, format, provider);
//Console.WriteLine("{0} converts to {1}.", dateString, result.ToString());
}
catch (Exception exc)
{
catchError(exc);
}
return result;
}
我将参数从页面发送到此方法:
protected void Page_Load(object sender, EventArgs e)
{
if(gm.isOk((string)Session["userid"])){
var sqlAry = "SELECT sno,std_name,gender,nic,father_name,father_nic,guardian_name,guardian_nic,dob,domicile,addres,reg_date,last_institute FROM std_basic_info WHERE sno = " + (string)Session["std_sno"];
DataTable data = gm.dataTable(sqlAry);
foreach (DataRow row in data.Rows)
{
snoTbl = row["sno"].ToString();
std_nameTbl = row["std_name"].ToString();
genderTbl = row["gender"].ToString();
nicTbl = row["nic"].ToString();
father_nameTbl = row["father_name"].ToString();
father_nicTbl = row["father_nic"].ToString();
guardian_nameTbl = row["guardian_name"].ToString();
guardian_nicTbl = row["guardian_nic"].ToString();
dobTbl = row["dob"].ToString();
domicileTbl = row["domicile"].ToString();
addresTbl = row["addres"].ToString();
reg_dateTbl = row["reg_date"].ToString();
institutionLstAttendedTbl = row["last_institute"].ToString();
}
this.std_sno.Value = snoTbl;
this.stdName.Text = std_nameTbl;
if (genderTbl.Equals("1")) { this.sex.SelectedIndex = 0; } else { this.sex.SelectedIndex = 1; }
this.stdNic.Text = nicTbl;
this.fatherName.Text = father_nameTbl;
this.fatherNic.Text = father_nicTbl;
this.guardianName.Text = guardian_nameTbl;
this.guardianNic.Text = guardian_nicTbl;
this.dob.Text = gm.mySqlDateFormate(dobTbl,"d").ToString();
this.domicile.Text = domicileTbl;
this.institutionLstAttended.Text = institutionLstAttendedTbl;
this.address.Text = addresTbl;
}
}
在 mySql 表中 dob 列的值如下:
1978-04-23
一切都很好,但是当它从表中获取值时,它显示如下:
1/1/0001 12:00:00 AM
我没有在我的文本字段中获得原始值?
请任何人帮助我...
谢谢