sqlite时间戳格式化 [英] sqlite timestamp formatting
问题描述
我想在sqlite数据库中使用日期。我将日期存储为时间戳,但是当我使用strftime()将它们格式化为人类可读的日期时,我回到不可预测的结果。
考虑以下内容,我选择当前时间戳记:
SELECT strftime(%s,now);
1281353727
然后我尝试使用我知道代表的时间戳格式化日期希望获得今天日期的人类可读格式:
SELECT strftime('%d - %m - %Y' 1281353727);
01 - 04 - 3503
而是获得上述结果。这是正确的行为吗?
提前感谢,
Kevin
<您需要先将时间戳转换为datetime:
SELECT strftime('%d - %m - %Y',datetime(1281353727,'unixepoch'))FROM Visits;
I am trying to work with dates in an sqlite database. I am storing my dates as timestamps, but when I use strftime() to format them to human readable dates I am getting back unxpected results.
Consider the following, I select the current timestamp:
SELECT strftime("%s","now");
1281353727
Then I try to format a date using the timestamp that I know to represent now expecting to get back a human readable format of todays date:
SELECT strftime('%d - %m - %Y ', 1281353727);
01 - 04 - 3503
Instead I get the above result. Is this correct behaviour? am I doing something wrong?
Thanks in advance,
Kevin
You need to convert the timestamp to datetime first:
SELECT strftime('%d - %m - %Y ', datetime(1281353727, 'unixepoch')) FROM Visits;
这篇关于sqlite时间戳格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!