sqlite时间戳格式化 [英] sqlite timestamp formatting

查看:462
本文介绍了sqlite时间戳格式化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆