1

I am using two different Datepickers to select the start and end date.For the day and month and year I choose, I want to get the moment that day began.For example 18 September 2018, 18 September 2018 and the hour 00.00. I would like to disable GMT differences if possible. With datepicker, I share the logs for the dates I selected.

D/START DATE: Sun Sep 23 18:23:51 GMT+03:00 2018
D/END DATE: Sun Sep 30 18:23:51 GMT+03:00 2018

The logs I want are as follows:

D/START DATE: Sun Sep 23 00:00:00 2018
D/END DATE: Sun Sep 30 23:59:59 2018

This means that any time within the start day must be valid and any time until the end date ends for the end date. How do I make that happen?

fatih
  • 1,285
  • 11
  • 27
  • Consider java.time, the modern Java date and time API. It’s generally much nicer to work with and in particular better suited for a filtering task like yours. If you are coding for less that new Android, add the ThreeTenABP library to your project to use java.time, see [How to use ThreeTenABP in Android Project](https://stackoverflow.com/questions/38922754/how-to-use-threetenabp-in-android-project). – Ole V.V. Sep 30 '18 at 02:53
  • Use half-open intervals: When the user picks Sep 23 and 30, include times that are on or after Sep 23 at 00:00 and **strictly before Oct 1 at 00:00**. Do keep the GMT offset, or you won’t be able to tell whether a time is before or after these limits. – Ole V.V. Sep 30 '18 at 02:55

2 Answers2

3

You can change your calendar value like this:

yourTime.set(Calendar.HOUR_OF_DAY,0);
yourTime.set(Calendar.MINUTE,0);
yourTime.set(Calendar.SECOND,0);

Or

yourTime.set(Calendar.HOUR_OF_DAY,23);
yourTime.set(Calendar.MINUTE,59);
yourTime.set(Calendar.SECOND,59);

Where yourTime is Calendar instance. Hope it would help.

Andrew
  • 471
  • 3
  • 13
1

https://developer.android.com/reference/java/text/SimpleDateFormat

String dateOfDay = new SimpleDateFormat("dd MM yyyy").format(new Date());
String time = android.text.format.DateFormat.format("HH:mm:ss", new Date().getTime()).toString();

That could be the answer you're looking for. You can also find shortcuts in the top link.

Trk
  • 95
  • 1
  • 12