I want to retrieve data from a particular date from Firebase
. They are stored in the following format:
I am using a datePicker
to choose a date. But I am not able to figure out how I can change the date chosen to the above format.
For example: I choose a date say 28th March 2018
. I would use the code:
int day = datePicker.getDayOfMonth();
String month = datePicker.getMonth() + "";
String year = datePicker.getYear() + "";
But I am not able to figure out how to change it to the following format, Wed Mar 28 2018 00:00:00 GMT+530 (IST)
After spending hours, trying to figure out a way, I have finally found a solution and have realized that this was a pretty silly question to ask. Nevertheless, this is what I have come up with,
int day = datePicker.getDayOfMonth();
int year = datePicker.getYear();
int month = datePicker.getMonth() + 1;
try {
SimpleDateFormat sdf = new SimpleDateFormat("d-M-yyyy");
Date date = sdf.parse(day + "-" + month + "-" + year);
sdf = new SimpleDateFormat("EEE MMM dd yyyy");
String strDate = sdf.format(date) + " 00:00:00 GMT+0530 (IST)";
Log.d("date_simple", strDate);
} catch (ParseException e) {
Log.d("date_simple", e + "");
e.printStackTrace();
}
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.