再读取不可控数据库datetime字段时,遇到了一个奇葩问题——“无法识别的datetime格式”

搞了半天……

数据库里看:2017-06-06 10:28:30.000

不做处理查询报错:“无法识别的datetime格式”

做处理后查出来个:42892.4364583333

……

接下来这么处理

DateTime dtr = DateTime.FromOADate(42863.5656134259);
double ewr = dtr.ToOADate();
DateTime val = new DateTime(1899, 12, 31);
val = val.AddDays(42863.5656134259);
SQLiteConnection connection= new SQLiteConnection(string.Format(
"Data Source={0}skpdb_539900210037.db3;Version=3;",
AppDomain.CurrentDomain.SetupInformation.ApplicationBase));//
connection.Open();
DataTable dt = new DataTable();
//connection.Open();
SQLiteCommand command = new SQLiteCommand(connection);
command.CommandText = "select CAST(kprq AS double) from zzs_fpkj order by kprq";
SQLiteDataAdapter adapter = new SQLiteDataAdapter(command);
adapter.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
string aaa = DateTime.FromOADate(Convert.ToDouble(dr[0])).ToString();
Console.WriteLine(aaa);
}
connection.Close();

  

C# sqlite 无法识别的datetime格式 FromOADate的更多相关文章

  1. 标准 DateTime 格式字符串

    标准 DateTime 格式字符串 MSDN 标准 DateTime 格式字符串包含一个标准 DateTime 格式说明符字符,该字符表示自定义 DateTime 格式字符串.格式字符串最终定义由格式 ...

  2. 字定义JSON序列化支持datetime格式序列化

    字定义JSON序列化支持datetime格式序列化 由于json.dumps无法处理datetime日期,所以可以通过自定义处理器来做扩展,如: import json from datetime i ...

  3. php 当前时间 当前时间戳和数据库里取出的时间datetime格式进行比较大小

    php 当前时间 当前时间戳和数据库里取出的时间datetime格式进行比较大小 UNIX时间戳转换为日期用函数: date() ,date('Y-m-d H:i:s', 1500219870); 日 ...

  4. 常用SQL时间格式SQLServer中文版的默认的日期字段datetime格式是yyyy-mm-d

    常用SQL时间格式 SQL Server中文版的默认的日期字段datetime格式是yyyy-mm-dd Thh:mm:ss.mmm 例如: select getdate() -- ::08.177 ...

  5. C# 代码往oracle数据库添加datetime格式列

    C# 代码往oracle数据库添加datetime格式列时,不需要在insert语句中为datetime类型使用to_date函数

  6. c# dateTime格式转换为Unix时间戳工具类

    using System; using System.Collections.Generic; using System.Text; namespace TJCFinanceWriteOff.BizL ...

  7. C# DATETIME格式转换汇总 根据日期获取星期

    原文:C# DATETIME格式转换汇总 根据日期获取星期 C# DateTime.Now.Year --2019(年) DateTime.Now.Month --9(月) DateTime.Now. ...

  8. C#、js、json Datetime格式总结

    在工作过程中遇到时间格式的数据在C#.js 和 json保存的不同结果,现在总结一下 JavaScript Parser: 1.数字型时间转字符串时间 如var data = "/Date( ...

  9. ASP.NET Core 返回 Json DateTime 格式

    ASP.NET Core 返回 Json 格式的时候,如果返回数据中有DateTime类型,如何自定义其格式呢?配置如下: services.AddMvc().AddJsonOptions(opt = ...

随机推荐

  1. lua基础(2)

    错误处理: local function add(a,b) assert(type(a) == "number", "a 不是一个数字") assert(typ ...

  2. IIS下设置跨域访问问题--Access-Control-Allow-Origin 站点跨域请求的问题

    背景: 最近 开发中遇到新需求,把公司的OA系统迁移一套到小程序上面去 有些功能的信息是在小程序 查看 但是文件是在pc端上传的 例如:领导在外出办公 使用小程序查看xxxx.pdf文件  这个时候就 ...

  3. 安装wordpress的过程

    1 首先安装lamp.在安装php时,由于ubuntu16.04源中自带的是php7,所以需要直接安装 apt-get install phpapt-get install libapache2-mo ...

  4. Codeforces Round #575 (Div. 3) E. Connected Component on a Chessboard(思维,构造)

    E. Connected Component on a Chessboard time limit per test2 seconds memory limit per test256 megabyt ...

  5. CSS3书写规范

    css样式的书写顺序: 1.位置属性(position, top, right, z-index, display, float等) 2.大小(width, height, padding, marg ...

  6. 指数家族-Beta分布

    2. Beta分布 2.1 Beta分布 我们将由几个问题来得引出几个分布: 问题一:1:  2:把这个  个随机变量排序后得到顺序统计量  3:问  是什么分布 首先我们尝试计算  落在一个区间   ...

  7. JAVA笔记20-容器之四Map接口、自动打包、泛型(重要)

    一.Map接口 Map提供的是key到value的映射.key不能重复,每个key只能映射一个value. 注:重复是指equals,但用equals()方法效率低,所以此处用hashCode()方法 ...

  8. 【curl】cookie的分隔符

    cookie是以分号作为分隔符的. ex: curl --silent -H "Host: xxx.com" "172.172.178.9:80/item/comm?pi ...

  9. Apollo配置中心环境搭建(Linux)

    官方教程:https://github.com/ctripcorp/apollo/wiki/Apollo-Quick-Start-Docker%E9%83%A8%E7%BD%B2 方式二:使用apol ...

  10. WEB上传大文件

    众所皆知,web上传大文件,一直是一个痛.上传文件大小限制,页面响应时间超时.这些都是web开发所必须直面的. 本文给出的解决方案是:前端实现数据流分片长传,后面接收完毕后合并文件的思路.下面贴出简易 ...