MongoDB DateTime Format

后端 未结 5 1018
遇见更好的自我
遇见更好的自我 2021-01-16 08:25

In mongodb adhoc query, before executing the query, how to format the date type element to dd\\mm\\yyyy format and then execute the query?

5条回答
  •  抹茶落季
    2021-01-16 09:05

    Date class has a before(date) or after(date) method... It is easy to use: no conversion to seconds/milliseconds.

    public void execute(Tuple input) {
        try {
            date=(Date) input.getValueByField("date");
            boolean before = date.before(myDate); // compare the data retrieved with your date.
            if (before) {
                ...
            } else {
                ...
            }
        } catch (Exception e) {
            logger.error("Error...", e);
        }
    

    This approach is easier than the accepted answer..

提交回复
热议问题