I am attempting to compare the current date and time with a date and time in parse. I would like the query to only return the events that have not closed for their registering period which would be their "end" date. But for some reason my parameters are not working the code is the following:
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());// gets current date and time
query.whereGreaterThanOrEqualTo("end", currentDateTimeString);// should compare the dates and if the end date is past the current moment and time of this query not display that event
just use Date indeed if a String. the Parse Date Col. are comparable to Date.
query.whereGreaterThanOrEqualTo("end", new Date());
You can use Joda Time library. See the example below
LocalDate startDate = new LocalDate(2014, 1, 2);
LocalDateTime startDateTime = new LocalDateTime(2014, 1, 2, 14, 0);
LocalDate forCompare = startDateTime.toLocalDate();
System.out.println("equal dates: " + forCompare.equals(startDate));
Try something like this. Send the DateChecker function a date and if that date is before the the current date return true. If it is not return false.
public bool DateChecker(DateTime dt){
if(DateTime.Now.Day<=dt.Day && DateTime.Now.Month<=dt.Month && DateTime.Now.Year<=dt.Year)){
return true;
}
else{
return false;
}
}
//BELOW CODE GOES IN A DIFFERENT FUNCTION
DateTime? dt;
var yourQuery = ParseObject.GetQuery ("YourClass");
yourQuery.FindAsync ().ContinueWith (task => {
if(!task.IsCompleted){
return;
}
if(task.IsCompleted){
IEnumerable<ParseObject> results = task.Result;
foreach(ParseObject result in results){
string oid = "";
if(result.ObjectId!=null){
oid = result.ObjectId;
}else{
oid = "1337";
}
dt = result.("YourDateColumn in parse");
DateTime tmpDate;
tmpDate = dt ?? DateTime.Now;
if (tmpDate.Year == DateTime.Now.Year && tmpDate.Month == DateTime.Now.Month && DateChecker (tmpDate)) {
//adds items for this time period only
}
}
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.