Converting long value(epoch) to Date format using

2019-08-22 13:20发布

I have vertex created date in long format (epoch). I want to convert the long value into particular date format (YYYY-MM or YYYY-MM-DD) using gremlin query. .map or .transform is not working. Can someone please help.

1条回答
Bombasti
2楼-- · 2019-08-22 13:56

The Gremlin language doesn't have built in features to convert dates. You would have to use a lambda if you want to do it within Gremlin - for Groovy it would look like:

gremlin> g = TinkerGraph.open().traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.addV('person').property('dob',Date.parse('yyyy-MM-dd','2018-10-01').getTime())
==>v[0]
gremlin> g.V().valueMap()
==>[dob:[1538366400000]]
gremlin> g.V().values('dob').map{new Date(it.get()).format('yyyy-MM-dd')}
==>2018-10-01

You could write the same in Java by skipping the shorthand Groovy provides and just using SimpleDateTime in the lambda. Of course, TinkerPop advises against lambdas and in this case, I think that the better solution is to simply return your result as a Long and then transform it on the client as needed once in hand.

查看更多
登录 后发表回答