再读取不可控数据库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. tensorflow 屏蔽 Log

    pip install alfred-py 在代码中加入 from alfred.dl.tf.common import mute_tf mute_tf()

  2. 解决Kloxo出现Could not open database connection问题

    当我们在使用或者运行kloxo面板的时候,可能会出现类似"Could not open database connection"错误提示,对于新手朋友来说肯定本身安装面板管理VPS ...

  3. RPC框架pigeon源码分析

    Pigeon是一个分布式服务通信框架(RPC),是美团点评最基础的底层框架之一.已开源,链接:https://github.com/dianping/pigeon 从接下来三个方面来分析pigeon的 ...

  4. 前端每日实战:158# 视频演示如何用纯 CSS 创作一个雨伞 toggle 控件

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/pxLbjv 可交互视频 此视频是可 ...

  5. 在vue-cli中使用px2rem,配合lib-flexible使用

    原文地址 附上github源码  看这里 1.下载lib-flexible npm安装 npm i lib-flexible --save 2.引入lib-flexible 在main.js中引入li ...

  6. python接口自动化二(发送post请求)

    前言 一个http请求包括三个部分,为别为请求行,请求报头,消息主体,类似以下这样: 请求行 请求报头 消息主体 HTTP协议规定post提交的数据必须放在消息主体中,但是协议并没有规定必须使用什么编 ...

  7. 导入本地Excel到DataSet中

    /// <summary> /// 导入本地Excel到DataSet中 /// </summary> /// <param name="strFileSour ...

  8. maven项目使用自己创建的jar包--maven without test code

    eclipse版本为2018-12(4.10.0) 1.创建一个jar包 首先自己建立了一个maven project,名为jweb.GAV坐标: <groupId>amberai< ...

  9. SQL 使用分区方法

  10. UVa 1600 Patrol Robot (BFS最短路 && 略不一样的vis标记)

    题意 : 机器人要从一个m * n 网格的左上角(1,1) 走到右下角(m, n).网格中的一些格子是空地(用0表示),其他格子是障碍(用1表示).机器人每次可以往4个方向走一格,但不能连续地穿越k( ...