将时间跨度解析为字符串c#

时间:2016-10-25 14:02:08

标签: c# sql

我在转换timespan时遇到困难,在sql server中,jamulai列数据类型为time

private void btntambah_Click(object sender, EventArgs e)
{
    int kodejadwal = Int32.Parse(txtkode.Text);
    string hari = txthari.Text;
    TimeSpan jamulai = new TimeSpan (txtjam.Text);
    string jamselesai = txtjam2.Text;

    this.jadwalPraktekTableAdapter.Insert(hari, jamulai, jamselesai);
    this.jadwalPraktekTableAdapter.Fill(healthy_CareDataSet.JadwalPraktek);
}

2 个答案:

答案 0 :(得分:2)

要将时间跨度转换为字符串,您只需使用key outside find(): themes/seven/reset.css key outside find(): themes/seven/style.css key outside find(): sites/all/modules/ctools/css/ctools.css key outside find(): modules/dblog/dblog.css key outside find(): modules/overlay/overlay-child.css key outside find(): sites/all/modules/panels/css/panels.css key outside find(): modules/system/system.base.css key outside find(): modules/system/system.admin.css key outside find(): modules/system/system.menus.css key outside find(): modules/system/system.messages.css key outside find(): modules/system/system.theme.css key outside find(): sites/all/modules/date/date_api/date.css key outside find(): modules/field/theme/field.css key outside find(): modules/node/node.css key outside find(): modules/search/search.css key outside find(): modules/user/user.css key outside find(): sites/all/modules/views/css/views.css executed key inside find(): sites/all/modules/views/css/views.css key inside find(): sites/all/modules/views/css/views.css key inside find(): sites/all/modules/views/css/views.css key inside find(): sites/all/modules/views/css/views.css key inside find(): sites/all/modules/views/css/views.css key inside find(): sites/all/modules/views/css/views.css key inside find(): sites/all/modules/views/css/views.css key inside find(): sites/all/modules/views/css/views.css key inside find(): sites/all/modules/views/css/views.css key inside find(): sites/all/modules/views/css/views.css key inside find(): sites/all/modules/views/css/views.css key inside find(): sites/all/modules/views/css/views.css key inside find(): sites/all/modules/views/css/views.css key inside find(): sites/all/modules/views/css/views.css key inside find(): sites/all/modules/views/css/views.css key inside find(): sites/all/modules/views/css/views.css key inside find(): sites/all/modules/views/css/views.css

即可

在您的情况下,您需要timespan.ToString()

要格式化时间跨度以适应MySQL的时间格式,您需要执行以下操作:

jamulai.ToString()

答案 1 :(得分:2)

  1. 请阅读TimeSpanHere
  2. 的文档
  3. 并自定义TimeSpan字符串格式:Here
  4. 只需按照TimeSpan的文档进行操作,然后输入您需要的格式。