如何转换Thu Apr 06 14:30:00 IST 2017为此格式2017-07-05T16:50:22.490在N1QL查询

时间:2017-07-07 06:59:10

标签: couchbase n1ql

如何转换" Thu Apr 06 14:30:00 IST 2017"对于这种格式 " 2017-07-05T16:50:22.490"在N1QL查询中

2 个答案:

答案 0 :(得分:0)

在将其插入Couchbase之前,当您从其他服务获取日期时,您必须先将其转换为毫秒。完成此操作后,您可以使用MILLIS_TO_STR日期功能将其转换为您想要的格式。格式列表和日期函数描述在

中给出

https://developer.couchbase.com/documentation/server/current/n1ql/n1ql-language-reference/datefun.html

答案 1 :(得分:0)

感谢kbinstance,它在转换为毫秒后得到解决

String fulfillmenttime1 = "Thu Apr 06 14:30:01 IST 2017";
SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
Date date1 = formatter.parse(fulfillmenttime1);
long longfulfillmenttime1 = date1.getTime();

使用Collections.sort后,它已经排序了。不需要使用n1ql查询。