久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

SQLite.Net-PCL 如何處理 UTC 時間

How SQLite.Net-PCL handle UTC time(SQLite.Net-PCL 如何處理 UTC 時間)
本文介紹了SQLite.Net-PCL 如何處理 UTC 時間的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在使用以下代碼:

使用 new SQLite.Net.SQLiteConnection(new SQLitePlatformWinRT(), DBPath) 獲取 SQLiteConnection并創(chuàng)建表.

類包含日期時間數據類型

class 交易{[SQLite.Net.Attributes.PrimaryKey, SQLite.Net.Attributes.AutoIncrement]公共 int QId { 獲取;放;}公共日期時間購買日期{獲取;放;}公共整數金額{get;set;}公共字符串 ItemCode {get;set;}}

插入數據如下:

var db = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), DBPath);var newItem = new Transaction(){購買日期 = 日期時間.現在,金額 = 100,項目代碼 = "ABC-C10"};db.Insert(newItem);

日期將存儲為 Ticks(例如 636071680313888433),這是 UTC 時間.

1) 使用上面的 DateTime.Now,如果我的電腦時間設置是

1a) 英國時間,

上面的代碼:purchase = DateTime.Now 能正確轉換嗎?

1b) 在美國時間,

上面的代碼:purchase = DateTime.Now 能正確轉換嗎?

如何在 SQL 語句中處理這個勾號?

如何從某個日期范圍內選擇所有交易?比如說,2016 年 7 月 10 日到 2016 年 7 月 20 日?

謝謝

解決方案

處理日期最安全的方法是使用 DateTimeOffset 類型而不是 DateTime.

DateTime 不包含創(chuàng)建時區(qū)的信息,它只知道它是 UTC 時間還是本地時間,如果數據要在不同的地方使用.

DateTimeOffset 不僅包含時間和日期信息,還包含時區(qū),這意味著結果將始終如您所愿.

使用方式沒有區(qū)別,只是改變了類型:

class 交易{[SQLite.Net.Attributes.PrimaryKey, SQLite.Net.Attributes.AutoIncrement]公共 int QId { 獲取;放;}公共日期時間偏移購買日期{獲取;放;}公共整數金額{get;set;}公共字符串 ItemCode {get;set;}}

對于數據庫訪問:

var db = new SQLite.Net.SQLiteConnection(新 SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), DBPath);var newItem = new Transaction(){PurchaseDate = DateTimeOffset.Now,//或使用DateTimeOffset.UtcNow作為UTC日期時間金額 = 100,項目代碼 = "ABC-C10"};db.Insert(newItem);

I am using below code:

using new SQLite.Net.SQLiteConnection(new SQLitePlatformWinRT(), DBPath) to get SQLiteConnection and create table.

Class contain DateTime DataType

class Transaction 
    {
        [SQLite.Net.Attributes.PrimaryKey, SQLite.Net.Attributes.AutoIncrement]
        public int QId { get; set; }
        public DateTime PurchaseDate { get; set; }  
        public int Amount {get;set;}
        Public string ItemCode {get;set;}      
    }

Insert Data As follows:

var db = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), DBPath);

 var newItem = new Transaction()
  {  
     PurchaseDate = DateTime.Now,            
     Amount = 100,
     ItemCode = "Abc-C10"               
  };

 db.Insert(newItem);

The date will be stored as Ticks(e.g. 636071680313888433) and this is UTC time.

1) using above DateTime.Now, If my Computer time setting is

1a) in British Time,

will the above code : purchase = DateTime.Now be converted correctly?

1b) in Usa Time,

will the above code : purchase = DateTime.Now be converted correctly?

How to handle this tick in SQL-statement?

How to select all transaction from ,say, a date range ? say , 2016-07-10 to 2016-07-20 ?

Thanks

解決方案

The safest way to work with dates is to use the DateTimeOffset type instead of DateTime.

DateTime does not contain the information about the time zone in which it was created, all it knows is whether it is in UTC or local time, which is not enough if the data is going to be used in different locations.

DateTimeOffset contains not only the time and date information, but also the time zone, which means the result will always be what you expect.

There are no differences in the way it is used, just change the type:

class Transaction 
{
    [SQLite.Net.Attributes.PrimaryKey, SQLite.Net.Attributes.AutoIncrement]
    public int QId { get; set; }
    public DateTimeOffset PurchaseDate { get; set; }  
    public int Amount {get;set;}
    Public string ItemCode {get;set;}      
}

For database access:

var db = new SQLite.Net.SQLiteConnection(
   new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), DBPath);

var newItem = new Transaction()
  {  
     PurchaseDate = DateTimeOffset.Now, //or use DateTimeOffset.UtcNow for UTC datetime           
     Amount = 100,
     ItemCode = "Abc-C10"               
  };

 db.Insert(newItem);

這篇關于SQLite.Net-PCL 如何處理 UTC 時間的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

Dynamically creating a placeholder to insert many column values for a row in SQLite table(動態(tài)創(chuàng)建占位符以在 SQLite 表中為一行插入多個列值)
How to make SQLite SELECT query in C correctly?(如何在 C 中正確地進行 SQLite SELECT 查詢?)
Timestamp with 9 digits in SQLite file(SQLite 文件中的 9 位時間戳)
Replace path string in SQLite DB causes unexpected violated unique constraint(替換 SQLite DB 中的路徑字符串導致意外違反唯一約束)
reading in many tables from SQLlite databases and combining in R(從 SQLlite 數據庫中讀取許多表并在 R 中組合)
defining a quot;VARIANTquot; column type in SQLite?(定義“變體SQLite 中的列類型?)
主站蜘蛛池模板: 国产91在线播放 | 国产在线资源 | 欧美精品一区在线发布 | 欧美不卡一区二区三区 | 国产91精品在线 | 福利在线观看 | 国产一区二区在线免费观看 | 91视频免费黄 | www.av在线 | 激情av在线 | 精品无码久久久久国产 | 欧美性video 精品亚洲一区二区 | 精品一区二区三区四区在线 | 国产精品一二区 | 99久久免费精品国产男女高不卡 | 一级国产精品一级国产精品片 | 欧美二区乱c黑人 | 亚洲国产精品99久久久久久久久 | 极品久久 | 国产精品久久久久久久免费观看 | 97视频成人| 天堂av影院| 欧美一区视频 | 日韩欧美在线视频观看 | 羞羞视频网站免费观看 | 一区二区三区视频在线 | 久久99深爱久久99精品 | 天天干天天操天天爽 | 精品成人佐山爱一区二区 | 久久狠狠| 国产精品久久久久久久久久久久久 | 无毛av| 狠狠色综合网站久久久久久久 | 欧美日韩一区二区在线 | 亚洲三区在线观看 | 一区天堂 | h片在线看 | 日本久草| 91精品国产色综合久久 | 成人美女免费网站视频 | 青青久久av北条麻妃海外网 |