最近在使用SQLite的数据库,发现SQLiteConnection类,有一个属性DateTimeKind

去msdn上找了下资料,http://msdn.microsoft.com/en-us/library/shx7s921(v=vs.110).aspx

写了一个demo加深理解,代码已经上传至https://github.com/chucklu/Test/blob/master/DotNetFrameworkClassLibrary/System/DateTimeKind/DateTimeKindDemo/Program.cs

想学习,如何使用git和github的同学,可以加我的qq群   程序员之家146605007

 /// <summary>
/// DateTimeKind测试
/// </summary>
class Program
{
static readonly string dateTimeFormat = "yyyy-MM-dd HH:mm:ss";
static void Main(string[] args)
{
DateTime now = DateTime.Now;
DateTime utcNow = DateTime.UtcNow;
Console.WriteLine(string.Format("Local时间{0}", now.ToString(dateTimeFormat)));
Console.WriteLine(string.Format("UTC时间{0}", utcNow.ToString(dateTimeFormat))); Console.WriteLine(); DateTime tmpTime;
tmpTime = now.ToUniversalTime();
Console.WriteLine(string.Format("Local时间转换为UTC时间 {0}", tmpTime.ToString(dateTimeFormat))); tmpTime = utcNow.ToLocalTime();
Console.WriteLine(string.Format("UTC时间转换为Local时间 {0}", tmpTime.ToString(dateTimeFormat))); Console.WriteLine(); //系统时区,为北京时间
tmpTime = DateTime.SpecifyKind(now,DateTimeKind.Unspecified);
//未指定时间的话,转换Local的时候,时间默认为UTC的,加上当前系统的时区的时差+8,也就是加上8个小时
Console.WriteLine(string.Format("Unspecified时间转换为Local时间 {0}", tmpTime.ToLocalTime().ToString(dateTimeFormat)));
//未指定时间的话,转换UTC的时候,时间默认为Local的,加上当前系统的时区的时差-8,也就是减去8个小时
Console.WriteLine(string.Format("Unspecified时间转换为UTC时间 {0}", tmpTime.ToUniversalTime().ToString(dateTimeFormat))); Console.ReadLine();
}
}

另外还需要吐槽下,SQLite的时间建议按照"yyyy-MM-dd HH:mm:ss"的格式进行插入,其他格式可以参考https://www.sqlite.org/lang_datefunc.html

bool类型必须按照"1或0"插入,不可以用true和false插入

虽然明白了DateTimeKind的作用,但是实际使用的时候,发现SQLite貌似不太支持

public DateTimeKind DateTimeKind { public get; public set; }
这个属性,设置和不设置,没有区别

 

System.DateTimeKind 的用法的更多相关文章

  1. C语言中system()函数的用法总结(转)

    system()函数功能强大,很多人用却对它的原理知之甚少先看linux版system函数的源码: #include <sys/types.h> #include <sys/wait ...

  2. alter system register的用法

    转自 http://blog.csdn.net/njyxfw/article/details/7516143 今天一个同事问到我,有没动态注册监听的命令,查了下,找到了alter system reg ...

  3. 与C中printf并列的System.out.printf 用法(转载)

    转载地址: https://blog.csdn.net/qq_39017218/article/details/80042287 printf的格式控制的完整格式: %  -  0  m.n  l或h ...

  4. 求System.arraycopy的用法

    public class Shuzufuzhi { public static void main(String args[]) {  int myArray[]={1,2,3,4,5,6};  in ...

  5. System.in的用法

    方法1 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));Scanner scanner=new Sca ...

  6. C# 定时执行方法: System.Timers.Timer用法示例

    System.Timers.Timer t = new System.Timers.Timer(5000); //设置时间间隔为5秒        private void Form1_Load(ob ...

  7. 简述System.Windows.Forms.Timer 与System.Timers.Timer用法区别

    System.Windows.Forms.Timer 基于窗体应用程序 阻塞同步 单线程 timer中处理时间较长则导致定时误差极大. System.Timers.Timer 基于服务 非阻塞异步 多 ...

  8. System.Timers.Timer用法

    System.Timers.Timer t = new System.Timers.Timer(5000); //设置时间间隔为5秒 private void Form1_Load(object se ...

  9. Java中System的详细用法

    System.arraycopy System.arraycopy的函数原型是: public static void arraycopy(Object src, int srcPos, Object ...

随机推荐

  1. MyBatis官方文档——XML 映射配置文件

    XML 映射配置文件 MyBatis 的配置文件包含了影响 MyBatis 行为甚深的设置(settings)和属性(properties)信息.文档的顶层结构如下: configuration 配置 ...

  2. (转)从程序员到CTO

    好好努力吧,向优秀的人看齐.文章来自http://blog.csdn.net/smarttony/article/details/6697617

  3. 代码片段,使用TIKA来解析PDF,WORD和EMAIL

    /** * com.jiaoyiping.pdstest.TestTika.java * Copyright (c) 2009 Hewlett-Packard Development Company, ...

  4. Egret打包App Android热更新(4.1.0)

    官网教程:http://developer.egret.com/cn/github/egret-docs/Native/native/hotUpdate/index.html 详细可看官网教程,我这里 ...

  5. linux下远程服务器批量执行命令及SFTP上传文件 -- python实现

    之前写过一个python远程执行命令的脚本,但在一个性能测试中,要将程序批量分发到不同服务器,程序无法使用,再将之前的脚本更新,加入批量上传的功能.之前脚本地址:http://www.cnblogs. ...

  6. nginx如何利用自定义的conf文件启动?

    1.进入nginx的安装目录; 2.nginx -s -c conf/my.conf  (校验该文件是否有效)   nginx -s -c conf/my.conf 命令会卡死,存疑 3.start ...

  7. 如何通过命令在Ubuntu中安装PyCharm

    对于Ubuntu 16.10和Ubuntu 17.04,通过Ctrl + Alt + T打开终端,或通过从应用启动器搜索“terminal”,打开后,执行以下步骤: 安装: 1.通过命令添加PPA存储 ...

  8. supervisor安装篇

    服务器环境: [root@kafka60 supervisor-]# uname -a Linux kafka60 -.el6.x86_64 # SMP Tue May :: UTC x86_64 x ...

  9. OA之为用户设置角色和为用户设置权限

    1.为用户设置角色 { Layout = null; } @using OA.Model <!DOCTYPE html> <html> <head> <met ...

  10. Python开发【Tornado】:异步Web服务(二)

    真正的 Tornado 异步非阻塞 前言: 其中 Tornado 的定义是 Web 框架和异步网络库,其中他具备有异步非阻塞能力,能解决他两个框架请求阻塞的问题,在需要并发能力时候就应该使用 Torn ...