Hello there
This statement doesn't work, but according to everything in Neo4j doc, it should.
RETURN apoc.date.parse('2020-11-14T18:22:06.327Z','s','yyyy-MM-ddThh:mm:ss.SSSZ')
yyyy-MM-ddThh:mm:ss.SSSZ Is a standard format
Hello there
This statement doesn't work, but according to everything in Neo4j doc, it should.
RETURN apoc.date.parse('2020-11-14T18:22:06.327Z','s','yyyy-MM-ddThh:mm:ss.SSSZ')
yyyy-MM-ddThh:mm:ss.SSSZ Is a standard format
RETURN apoc.date.format(apoc.date.fromISO8601('2011-11-14T18:22:06.327Z'), 'ms', 'yyyy-MM-dd HH:mm:ss:zzz')
Result:
"2011-11-14 18:22:06:UTC"
I actually needed to convert '2020-11-14T18:22:06.327Z' into seconds not ms.
But I found a workaround toInteger(apoc.date.fromISO8601('2011-11-14T18:22:06.327Z')/1000)
Fixed it!
I found when you look at the Neo4J APOC documentation and it's a bit vague, see if you can find the corresponding Java documentation. (A lot of APOC is a wrapper to call standard Java Functions.)
Here is a better explanation with examples:
https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
You had two errors (as I far as I can see):
Z
in the format string indicates the time zone offset. So, the parser is not expecting a Z
in the input string but rather +/-DD00
. To fix your input, I inserted -0000
(to indicate GMT). I'm not sure what timezone offset you really wanted.T
in the input string has to be matched with a quoted string in the format string. The parser barfed because T
isn't a recognized letter that matches a time component (like M
for month digit.) The fix is to use the quoted 'T'
in the format string to indicate a string literal.Also, if you use 's'
as the second argument, then your results will be in seconds.
RETURN apoc.date.parse(
"2020-11-14T18:22:06.327-0000", // input string
's', // 's' = seconds, 'ms' = milliseconds
"yyyy-MM-dd'T'HH:mm:ss.SSSZ" // Format string
)
1605378126
Thank you for the deep investigation @clem
I can't modify the input string, the purpose of it it's to be able to optimise and use properly only one dedicated function to convert an ISO8601 date to a linux timestamp expressed in seconds.
But I figure it out by removing the Z from your format string.
RETURN apoc.date.parse('2021-12-11T09:42:09.327Z','s',"yyyy-MM-dd'T'hh:mm:ss.SSS")