简体   繁体   English

SQL查询中本地时间的18位时间戳

[英]18 digit time stamp to local time within SQL query

I am using DB Browser for SQlite. 我正在为SQlite使用数据库浏览器。 My database also has date time stored in 18 digit time-stamp. 我的数据库还具有以18位时间戳记存储的日期时间。 Please help to convert it to Local Time within this query: 请在以下查询中帮助将其转换为本地时间:

SELECT * FROM message WHERE handle_id=52 ORDER BY date DESC;   

I believe that this is a type of unix timestamp since the db is mac based. 我相信这是unix时间戳的一种,因为数据库基于mac。 (Apple CoreD (nanosec) is the timestamp format, Thanks varro) Here are a couple of examples from the db: (Apple CoreD(nanosec)是时间戳格式,谢谢varro)这是db中的几个示例:

561774860770410304 559334672583377600   

I came across another similar question (18 digit timestamp to Local Time), but the asker didn't need the answer in any particular language or platform. 我遇到了另一个类似的问题(本地时间的18位时间戳),但询问者不需要任何特定语言或平台的答案。

Thanks, Alice 谢谢爱丽丝

Without knowing beforehand the timestamp format, it's impossible to give a definitive answer, but I submit this script (which depends on the sqlite3 command line tool only) to help: 如果不事先知道时间戳格式,就不可能给出确切的答案,但是我提交了这个脚本(仅取决于sqlite3命令行工具)来提供帮助:

#!/bin/sh

printf "Enter timestamp: "
read number

sqlite3 <<EOS
.mode column
.width 12, 20

select 'Number:',     $number;
select 'Unix epoch:', datetime($number, 'unixepoch');
select 'Variant:',    datetime($number, 'unixepoch', '-70 years');
select 'Julian day:', datetime($number);
select 'Mac HFS+:',   datetime($number, 'unixepoch', '-66 years');
select 'Apple CoreD:';
select '  (seconds)', datetime($number, 'unixepoch', '+31 years');
select '  (nanosec)', datetime($number/1000000000, 'unixepoch', '+31 years');
select 'NET:',        datetime($number/10000000, 'unixepoch', '-1969 years');
EOS

If you run this script and enter your number 561774860770410304 , you will see the following: 如果运行此脚本并输入号码561774860770410304 ,则会看到以下内容:

% Enter timestamp: 561774860770410304
Number:       561774860770410304
Unix epoch:   -
Variant:      -
Julian day:   -
Mac HFS+:     -
Apple CoreD:
  (seconds)   -
  (nanosec)   2018-10-21 00:34:20
NET:          1781-03-12 09:14:37

I will guess that probably "2018-10-21 00:34:20" is your timestamp, and that accordingly "Apple CoreD (nanosec)"" is your timestamp format (see https://www.epochconverter.com/coredata ). 我猜想可能是“ 2018-10-21 00:34:20”是您的时间戳,因此“ Apple CoreD(纳秒)”是您的时间戳格式(请参阅https://www.epochconverter.com/coredata ) 。

I think that your case might be like this: https://stackoverflow.com/a/36822906/10498828 . 我认为您的情况可能是这样的: https : //stackoverflow.com/a/36822906/10498828
The difference is that your date values are in nanoseconds, so you need first to divide with 1000000000: 区别在于您的日期值以纳秒为单位,因此您需要先除以1000000000:

select datetime(datecolumn/1000000000 + 978307200, 'unixepoch') from message 

For these values: 对于这些值:

561774860770410304 559334672583377600

the above code gives: 上面的代码给出:

2018-10-21 00:34:20 2018-09-22 18:44:32

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM