Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sqlite 朱利安日_Sqlite_Julian Date - Fatal编程技术网

Sqlite 朱利安日

Sqlite 朱利安日,sqlite,julian-date,Sqlite,Julian Date,我正在使用sqlite记录时间戳 INSERT INTO packets VALUES ( strftime('%%J','now') ); 然后提取经过的时间 SELECT strftime('%%J','now') - first_timestamp FROM packets; 这很有效。如果我等待一分钟,结果是0.0007(~=1*60/24*60*60) 我想在几小时、几分钟和几秒钟内看到这个,但是 sqlite> SELECT time(0.0007); 12:01:00

我正在使用sqlite记录时间戳

INSERT INTO packets VALUES ( strftime('%%J','now') );
然后提取经过的时间

SELECT strftime('%%J','now') - first_timestamp FROM packets;
这很有效。如果我等待一分钟,结果是0.0007(~=1*60/24*60*60)

我想在几小时、几分钟和几秒钟内看到这个,但是

sqlite> SELECT time(0.0007);
12:01:00
12是从哪里来的

这“有效”

sqlite> SELECT time(0.0007-0.5);
00:01:00
但似乎太过单薄,无法使用


根据CL的解释,我提交了这段代码

std::string TimeSinceFirstPacket()
{
    // open database
    Open();

    // read timestamp of first packet
    // this is stored as a Julian day for convenince in calculating and formatting the elapsed time
    // Note that for Julian days
    //   1.0 is 24 hours
    //    -0.5 represents the previous midnight
    // discussion at http://stackoverflow.com/q/38284268/16582

    int dbret = DB.Query(
             " SELECT "
             "       first_timestamp, "
             "       ( strftime('%%J','now') - first_timestamp ) < 1.0, "
             "       time( strftime('%%J','now') - first_timestamp - 0.5 ) "
             " FROM packets;");

    // check for successful db read
    if( dbret != 1 )
        return "error";

    // check that timestamp has been initialized
    if( DB.myResultA[ 0 ] == "0" )
        return "none";

    // check that elapsed time is less than 24 hours
    if( DB.myResultA[ 1 ] == "0" )
        return ">24hr";

    // return human readable hh::mm::ss elapsed time
    return DB.myResultA[ 2 ];
std::string timesinecfirstpacket()
{
//开放数据库
Open();
//读取第一个数据包的时间戳
//这被存储为儒略日,以便计算和格式化经过的时间
//请注意,对于朱利安时代
//1.0是24小时
//-0.5表示前一个午夜
//讨论http://stackoverflow.com/q/38284268/16582
int dbret=DB.Query(
“选择”
“第一个时间戳,”
(strftime('%J','now')-第一个时间戳)<1.0
时间(strftime('%J','now')-第一个\u时间戳-0.5)
“来自数据包;”;
//检查数据库读取是否成功
如果(dbret!=1)
返回“错误”;
//检查时间戳是否已初始化
if(DB.myResultA[0]=“0”)
返回“无”;
//检查运行时间是否少于24小时
if(DB.myResultA[1]=“0”)
返回“>24小时”;
//返回人类可读的hh::mm::ss运行时间
返回DB.myResultA[2];

朱利安的日子不是从午夜算起,而是从中午算起:

> select julianday('2000-01-01 00:00:00');
2451544.5
> select julianday('2000-01-01 12:00:00');
2451545.0

因此,要获得从午夜开始的时间,必须计算数字与表示午夜的数字之间的差值。

因此,表示前一个午夜的数字是-0.5