C# 关於DateTime的问题 这是预约房间的系统Book Time是想预约的时间Due Time是房间到期的时间预约房间的使用期为1小时在图中 我选了预约12点 房间到期的时间该是1点吧 为何在ListView显示的时间会不正确? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void Booking_Load(object sender, EventArgs e) { bookTime.Format = DateTimePickerFormat.Custom; bookTime.CustomFormat = "MM dd yyyy hh mm"; bookTime.Value = DateTime.Now; dueTime.Format = DateTimePickerFormat.Custom; dueTime.CustomFormat = "MM dd yyyy hh mm"; dueTime.Value = DateTime.Now; private void dueDate_ValueChanged(object sender, EventArgs e) { //check dueTime// dueTime.Value = bookTime.Value.AddMinutes(60); } private void btnConfirm_Click(object sender, EventArgs e) { /////confirm booking/// txtBookNo.ReadOnly = true; string bookNo = txtBookNo.Text; string sqlComfirm; OleDbCommand cmd; sqlComfirm = "INSERT INTO Book (" + "BookNo, " + "BookTime, " + "memberNo " + ") VALUES (" + toSql(int.Parse(txtBookNo.Text)) + ", " + toSql(bookTime.Value.ToLocalTime()) + ", " + toSql(memberNoComboBox.Text).ToString() + ")"; try { cmd = new OleDbCommand(sqlComfirm, mDB); cmd.ExecuteNonQuery(); MessageBox.Show("Booking inserted successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message); } btnBook.Enabled = true; } dueTime.Format = DateTimePickerFormat.Custom; dueTime.CustomFormat = "MM dd yyyy hh mm"; dueTime.Value = DateTime.Now; 你这里过期时间这样写是不对的,你这样写,过期时间只会保存了当前的时间,你是想保存预定时候的时间,你可以用一个临时变量来保存预定时候的时间,比如string DatetimeCahe=DateTime.Now.ToString().然后单击保存按钮的时候,可以用Convert.ToDateTime(DatetimeCahe).Value.AddMinutes(60); 不明白 + toSql(bookTime.Value.ToLocalTime()) + ", "这句要如何改 改为+ toSql(Convert.ToDateTime(DatetimeCahe)) + ", "还有就是bookTime.Format = DateTimePickerFormat.Custom; bookTime.CustomFormat = "MM dd yyyy hh mm"; bookTime.Value = DateTime.Now; //改为bookTime.Format = DateTimePickerFormat.Custom; bookTime.CustomFormat = "MM dd yyyy hh mm"; bookTime.Value = Convert.ToDateTime(DatetimeCahe) string DateTimeCahe="";//全局变量 private void dueDate_ValueChanged(object sender, EventArgs e) { //check dueTime// DateTimeCahe=DateTime.Now.ToString(); dueTime.Value = Convert.ToDateTime(DatetimeCahe).Value.AddMinutes(60); } ; private void btnConfirm_Click(object sender, EventArgs e) { /////confirm booking/// txtBookNo.ReadOnly = true; string bookNo = txtBookNo.Text; string sqlComfirm; OleDbCommand cmd; sqlComfirm = "INSERT INTO Book (" + "BookNo, " + "BookTime, " + "memberNo " + ") VALUES (" + toSql(int.Parse(txtBookNo.Text)) + ", " + toSql(Convert.ToDateTime(DatetimeCahe).Value)+ ", " + toSql(memberNoComboBox.Text).ToString() + ")"; try { cmd = new OleDbCommand(sqlComfirm, mDB); cmd.ExecuteNonQuery(); MessageBox.Show("Booking inserted successfully"); } catch (Exception ex) { MessageBox.Show(ex.Message); } btnBook.Enabled = true; } 如何开发QQ? 一个行转列的老问题 继续关注~~关于Windows程序的运行原理。 关键javascript 中变量的连接 , 在线等!!! 将winform程序做成解压缩版 单元格拖宽,怎么做?? SDK v2.0 下"由于目标机器积极拒绝,无法连接" 及时更新 对datagrid中显示的值直接进行修改,然后保存到数据库该怎么操作? 怎么看窗体已经显示? 求高手帮忙!——“/”应用程序中的服务器错误。 问大家一个socket异步通信的问题
{
bookTime.Format = DateTimePickerFormat.Custom;
bookTime.CustomFormat = "MM dd yyyy hh mm";
bookTime.Value = DateTime.Now; dueTime.Format = DateTimePickerFormat.Custom;
dueTime.CustomFormat = "MM dd yyyy hh mm";
dueTime.Value = DateTime.Now;
{
//check dueTime// dueTime.Value = bookTime.Value.AddMinutes(60);
}
{
/////confirm booking///
txtBookNo.ReadOnly = true; string bookNo = txtBookNo.Text; string sqlComfirm;
OleDbCommand cmd; sqlComfirm = "INSERT INTO Book ("
+ "BookNo, "
+ "BookTime, "
+ "memberNo " + ") VALUES (" + toSql(int.Parse(txtBookNo.Text)) + ", "
+ toSql(bookTime.Value.ToLocalTime()) + ", "
+ toSql(memberNoComboBox.Text).ToString() + ")";
try
{
cmd = new OleDbCommand(sqlComfirm, mDB);
cmd.ExecuteNonQuery();
MessageBox.Show("Booking inserted successfully");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
} btnBook.Enabled = true;
}
dueTime.CustomFormat = "MM dd yyyy hh mm";
dueTime.Value = DateTime.Now;
你这里过期时间这样写是不对的,你这样写,过期时间只会保存了当前的时间,你是想保存预定时候的时间,你可以用一个临时变量来保存预定时候的时间,比如string DatetimeCahe=DateTime.Now.ToString().然后单击保存按钮的时候,可以用Convert.ToDateTime(DatetimeCahe).Value.AddMinutes(60);
不明白
+ toSql(bookTime.Value.ToLocalTime()) + ", "
这句要如何改
还有就是bookTime.Format = DateTimePickerFormat.Custom;
bookTime.CustomFormat = "MM dd yyyy hh mm";
bookTime.Value = DateTime.Now; //
改为
bookTime.Format = DateTimePickerFormat.Custom;
bookTime.CustomFormat = "MM dd yyyy hh mm";
bookTime.Value = Convert.ToDateTime(DatetimeCahe)
string DateTimeCahe="";//全局变量
private void dueDate_ValueChanged(object sender, EventArgs e)
{
//check dueTime//
DateTimeCahe=DateTime.Now.ToString();
dueTime.Value = Convert.ToDateTime(DatetimeCahe).Value.AddMinutes(60); } ;
private void btnConfirm_Click(object sender, EventArgs e)
{
/////confirm booking///
txtBookNo.ReadOnly = true;
string bookNo = txtBookNo.Text; string sqlComfirm;
OleDbCommand cmd; sqlComfirm = "INSERT INTO Book ("
+ "BookNo, "
+ "BookTime, "
+ "memberNo " + ") VALUES (" + toSql(int.Parse(txtBookNo.Text)) + ", "
+ toSql(Convert.ToDateTime(DatetimeCahe).Value)+ ", "
+ toSql(memberNoComboBox.Text).ToString() + ")";
try
{
cmd = new OleDbCommand(sqlComfirm, mDB);
cmd.ExecuteNonQuery();
MessageBox.Show("Booking inserted successfully");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
} btnBook.Enabled = true;
}