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

SQLite.Net-PCL 如何處理 UTC 時(shí)間

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

問題描述

限時(shí)送ChatGPT賬號(hào)..

我正在使用以下代碼:

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

類包含日期時(shí)間數(shù)據(jù)類型

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

插入數(shù)據(jù)如下:

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

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

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

1a) 英國時(shí)間,

上面的代碼:purchase = DateTime.Now 能正確轉(zhuǎn)換嗎?

1b) 在美國時(shí)間,

上面的代碼:purchase = DateTime.Now 能正確轉(zhuǎn)換嗎?

如何在 SQL 語句中處理這個(gè)勾號(hào)?

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

謝謝

解決方案

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

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

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

使用方式?jīng)]有區(qū)別,只是改變了類型:

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

對(duì)于數(shù)據(jù)庫訪問:

var db = new SQLite.Net.SQLiteConnection(新 SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), DBPath);var newItem = new Transaction(){PurchaseDate = DateTimeOffset.Now,//或使用DateTimeOffset.UtcNow作為UTC日期時(shí)間金額 = 100,項(xiàng)目代碼 = "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);

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

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

相關(guān)文檔推薦

Dynamically creating a placeholder to insert many column values for a row in SQLite table(動(dòng)態(tài)創(chuàng)建占位符以在 SQLite 表中為一行插入多個(gè)列值)
How to make SQLite SELECT query in C correctly?(如何在 C 中正確地進(jìn)行 SQLite SELECT 查詢?)
Timestamp with 9 digits in SQLite file(SQLite 文件中的 9 位時(shí)間戳)
Replace path string in SQLite DB causes unexpected violated unique constraint(替換 SQLite DB 中的路徑字符串導(dǎo)致意外違反唯一約束)
reading in many tables from SQLlite databases and combining in R(從 SQLlite 數(shù)據(jù)庫中讀取許多表并在 R 中組合)
defining a quot;VARIANTquot; column type in SQLite?(定義“變體SQLite 中的列類型?)
主站蜘蛛池模板: 亚洲国产黄色 | 一级黄色片免费观看 | 婷婷综合五月天 | 白白色在线观看 | 99伊人网 | 国产极品在线观看 | 亚洲视频免费观看 | 伊人久久网站 | 99re在线视频| 国内精品一区二区 | 在线国产一区 | 五月天久久| 一级欧美一级日韩 | 玖玖精品在线 | 深夜福利在线播放 | 日韩亚洲欧美在线 | 黄色小视频免费 | 欧洲精品一区 | 久久久中文| 久久青青操| 中文字幕在线免费视频 | 狠狠干狠狠插 | 嫩草久久| 涩涩在线 | 中文在线观看免费视频 | 五月天黄色网址 | 精品国产91乱码一区二区三区 | 91精品看片| 日本免费黄色网址 | 亚洲成人精品 | 欧美在线免费观看 | 国产午夜精品一区二区三区视频 | 久久夜色精品国产欧美乱极品 | www.一级片| 91小视频在线观看 | 国产精品久久久久久久成人午夜 | 不卡av在线播放 | 色婷婷精品国产一区二区三区 | 精品伊人| 亚洲一区二区三区在线播放 | 国产精品成人免费视频 |