0

I need to filter an App Engine query by a date stamp that I've retrieved from a jsp as (strDatestamp). I know that the Datastore uses UTC time but I'm not sure how to account for this in my parsing. I've tried using Z, but this hasn't worked.

String strDatestamp = req.getParameter("datestamp");
    String myFormatString = "yyyy-MM-dd hh:mm:ss";
    Date datestamp = null;
    try {
        datestamp = new SimpleDateFormat(myFormatString, Locale.ENGLISH).parse(strDatestamp);
    } catch (ParseException e) {
        e.printStackTrace();
    }
Filter filter = new FilterPredicate("date", FilterOperator.EQUAL, datestamp);
Query query = new Query("Example", key)
                .setFilter(filter);

1 Answers1

1

This should parse the example string:

 String dt = "Mon Jul 15 13:44:52 UTC 2013";
 SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
 System.out.println(sdf.parse(dt));
nif
  • 3,154
  • 17
  • 18
  • @OP: just note that `SimpleDateFormat` is expensive to initialise, so share it between requests: http://stackoverflow.com/questions/4107839/synchronizing-access-to-simpledateformat/4108026#4108026 – Peter Knego Jul 16 '13 at 16:03