控件字符串格式化方法串串烧

winform

DataGridView

//桩号格式化

private void m_gridHDsp_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
      {
          if (e.ColumnIndex == 2)
          {
              int es = Convert.ToInt32(e.Value);
              e.Value = es / 1000 + "+" + es % 1000;
          }
      }

winform

时间格式化为 天数+小时+分+秒 不足位数补零

DateTime sDate = Convert.ToDateTime(dr.Cells["开启时间"].Value.ToString());
DateTime eDate = Convert.ToDateTime(dr.Cells["关闭时间"].Value.ToString());
//TimeSpan span = eDate - sDate;
//string totalhour = span.Days * 24 + span.Hours.ToString()+span.Minutes;
//-----201075162325修改----------
TimeSpan ts1 = new TimeSpan(sDate.Ticks);
TimeSpan ts2 = new TimeSpan(eDate.Ticks);
TimeSpan ts = ts1.Subtract(ts2).Duration();
string totalhour = string.Format("{0:00}", ts.Days * 24 + ts.Hours) + ":" + string.Format("{0:00}", ts.Minutes) + ":" + string.Format("{0:00}", ts.Seconds); ;

posted on 2010-05-30 13:21  澜紫癜青  阅读(174)  评论(0编辑  收藏  举报

导航