How to store time data type in neo4j?

﹥>﹥吖頭↗ 提交于 2019-12-11 09:55:16

问题


I created some user nodes with some value-time:

CREATE (u1:User {name:'user 1', pickUpTime:'10:10', dropOffTime:'10:35'})

I wonder what is a good way (format) to store time, because when i do this kind of queries

MATCH (u:User) RETURN u.name AS name, u.pickUpTime AS pickTime Order by pickTime desc

I got this as result

name    pickTime
user 3  9:30
user 2  10:20
user 1  10:10

And i need to get an ordered result:

 name   pickTime
 user 3  9:30
 user 1 10:10
 user 2 10:20

Any suggestions? Thanks in advance


回答1:


Two notes:

  1. You should use a format like HH:mm that means that you need to specify 9:30 as 09:30.

  2. Also in the previous case you need to specify "order by pickTime asc" and not desc if you would like to obtain the order you desire




回答2:


Time is a much trickier thing that it first appears, usually because time often refers back to a timezone, a date, or something else.

Many people will store the epoch time that they get from java via System.getCurrentTimeMillis(). They'll then convert it to whatever they need later on.

Other people will store the number of minutes after midnight if they're just looking for a relative time of day (i.e. 2:30PM)

Another option is to use Java Date objects as values. These are richer and allow you to express a timezone, calendar concepts, etc.

Storing them as strings is definitely a losing proposition for most use cases. Storing as something like a long integer permits direct comparison, but also requires that you convert something like an epoch time to a string that you really want, like "9:30"



来源:https://stackoverflow.com/questions/33463882/how-to-store-time-data-type-in-neo4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!