System.DateTimeKind 的用法
最近在使用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 的用法的更多相关文章
- C语言中system()函数的用法总结(转)
system()函数功能强大,很多人用却对它的原理知之甚少先看linux版system函数的源码: #include <sys/types.h> #include <sys/wait ...
- alter system register的用法
转自 http://blog.csdn.net/njyxfw/article/details/7516143 今天一个同事问到我,有没动态注册监听的命令,查了下,找到了alter system reg ...
- 与C中printf并列的System.out.printf 用法(转载)
转载地址: https://blog.csdn.net/qq_39017218/article/details/80042287 printf的格式控制的完整格式: % - 0 m.n l或h ...
- 求System.arraycopy的用法
public class Shuzufuzhi { public static void main(String args[]) { int myArray[]={1,2,3,4,5,6}; in ...
- System.in的用法
方法1 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));Scanner scanner=new Sca ...
- C# 定时执行方法: System.Timers.Timer用法示例
System.Timers.Timer t = new System.Timers.Timer(5000); //设置时间间隔为5秒 private void Form1_Load(ob ...
- 简述System.Windows.Forms.Timer 与System.Timers.Timer用法区别
System.Windows.Forms.Timer 基于窗体应用程序 阻塞同步 单线程 timer中处理时间较长则导致定时误差极大. System.Timers.Timer 基于服务 非阻塞异步 多 ...
- System.Timers.Timer用法
System.Timers.Timer t = new System.Timers.Timer(5000); //设置时间间隔为5秒 private void Form1_Load(object se ...
- Java中System的详细用法
System.arraycopy System.arraycopy的函数原型是: public static void arraycopy(Object src, int srcPos, Object ...
随机推荐
- 《转载》struts旅程《1》
struts简介 Struts是Apache软件基金会(ASF)赞助的一个开源项目.它最初是jakarta项目中的一个子项目,并在2004年3月成为ASF的顶级项目.它通过采用JavaServlet/ ...
- java反序列化漏洞的检测
1.首先下载常用的工具ysoserial 这边提供下载地址:https://jitpack.io/com/github/frohoff/ysoserial/master-v0.0.5-gb617b7b ...
- [NGINX] - 配置文件优化 - NGINX.CONF
Nginx 本文主要针对公司的Nginx负载均衡配置进行解释,配置文件在最下方.因为公司没有使用PHP,所以NGINX里面并没有太多facgi模块相关优化 NGINX.CONF user 语 ...
- 浙江工业大学校赛 画图游戏 BugZhu抽抽抽!!
BugZhu抽抽抽!! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- make linux test main attempt to index a nil value
Lua: getting started http://www.lua.org/start.html#learning Building from source Lua is very easy to ...
- Java Naming and Directory Interface (JNDI) Java 命名和目录接口
https://www.oracle.com/technetwork/java/jndi/index.html Lesson: Overview of JNDI (The Java™ Tutorial ...
- Qt::QWindow多窗口争抢置顶状态解决方案
有时候我们会有这种需求,自己的桌面程序需要置顶,但是程序包含了很多窗口,可能我们要求窗口1,2都在其它桌面程序之上,但是窗口1必须随时在窗口2之上. Qt提供的置顶方式是在windowsflags上增 ...
- Java 算法-快速幂
1 什么是快速幂? 快速幂,顾名思义就是快速的求次幂,例如:a^b,普通的算法就是累乘,这样的计算方法的时间复杂度就是O(n),而快速幂的方法使得次幂的计算方法的时间复杂度降低到O(logn). 假 ...
- http和socket之长连接和短连接区别
TCP/IP TCP/IP是个协议组,可分为三个层次:网络层.传输层和应用层. 在网络层有IP协议.ICMP协议.ARP协议.RARP协议和BOOTP协议. 在传输层中有TCP协议与UDP协议. 在应 ...
- Ftp服务器配置讲解
ftp.server.ip=192.168.80.130ftp.user=ftpuserftp.pass=ftpuserftp.server.http.prefix=http://image.imoo ...