在Postgresql中将时间存储在24:00:00以上的最佳方法? [英] Best way to store time above 24:00:00 in postgresql?

查看:204
本文介绍了在Postgresql中将时间存储在24:00:00以上的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将GTFS提要存储到SQL数据库中,并且预计某些时间会存储在时间值上限24:00:00之上。例如,某些火车在上午12:30开行,但已列出前几天的服务,在GTFS规范中,该行车时间存储为24:30。

I'm storing GTFS feeds into a SQL database and some times are expected to be stored above the 24:00:00 cap on time values. For example, some trains run at 12:30AM, but are listed for the previous days service, and that running time is stored as 24:30 in the GTFS specifications.

解决这个问题的最佳方法是什么?我应该只将它存储为字符串吗?

What would be the best way of getting around this? Should I just store it as a string?

推荐答案

建议为此使用int ...您的值可能是:

Suggest to use int for that... your value could be:

Sec + Min * 60 + Hour * 3600

对于24:30:00,您将获得88200。

For the 24:30:00, you will get 88200.

从数据库加载您的值时,您可以反转您的值通过简单的数学方程式:

When loading your value from DB, you could reverse your value by simple math equation:

Hour = int(value / 3600)
Min  = int(value % 3600 / 60)
Sec  = value % 3600 % 1800

这篇关于在Postgresql中将时间存储在24:00:00以上的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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