zoukankan      html  css  js  c++  java
  • DataGridView显示Datetime高精度字符串

    首先将 DataGridView 要是显示时间的列(比如StartTime) 设为String 类型.

    将对应的DateTable对应的列也设位String类型.

    DataRow row = dt.NewRow();

    Row["StartTime"] = DateTime.Now.ToString("HH:mm:ss fffffff");

    注意秒与 秒的小数部分要用一个空格分割, 否则, 会出错. 秒的小数位数最高位7位

    dt.Rows.Add(row);

    //如果数据架构已更改,则为 true;如果只有值发生了更改,则为 false

    bindingSource1.ResetBindings(false);// 相当于.net1.1 的bund 方法

    转回DateTime类型(也许保存到数据库里,想存为DateTime类型)

    /// <summary>

     /// change string time to datetime type, the string time like '17:07:08 0346690' 
    /// </summary>
     /// <param name="strTime">the string time like '17:07:08 0346690' </param>
     /// <returns>if successfully convert the time, return the date time, else return the DateTime.MinValue;.</returns>
          private DateTime ToDateTime(string strTime)
          {
              DateTime dt = DateTime.MinValue;
              try
              {
                  string[] strlist = strTime.Split(' ');
                  dt = Convert.ToDateTime(strlist[0]).AddTicks(Convert.ToInt32(strlist[1].PadRight(7,'0')));
              }
              catch
              { }
              return dt;
          }

  • 相关阅读:
    专业术语-外文首字母组词的原词组
    SQL-常用数据类型
    phpStudy-FTP_Server插件安装使用教程
    SQL-有关数据库的提问
    phpStudy-在使用phpMyAdmin报404Error
    phpStudy-坑爹的数据库管理器-phpMyAdmin的默认用户名和密码
    软件需求说明书-关键字-中英文
    Vim-命令合集
    Git-实验报告
    Git-进阶-远程仓库的使用
  • 原文地址:https://www.cnblogs.com/skyfei/p/775616.html
Copyright © 2011-2022 走看看