android-date

DatePickerDialog always opens the current date

霸气de小男生 提交于 2019-12-13 05:32:17
问题 I am having trouble with a DatePickerDialog , everytime I open it shows the current date not the date I set previously. Here's my code: final Calendar c = Calendar.getInstance(); final int mYear = c.get(Calendar.YEAR); final int mMonth = c.get(Calendar.MONTH); final int mDay = c.get(Calendar.DAY_OF_MONTH); DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() { // when dialog box is closed, below method will be called. public void onDateSet

How can I setMaxDate() for DatePicker to one month after the current date?

半腔热情 提交于 2019-12-12 18:51:34
问题 Here's my onCreateDialog : DatePickerDialog dialog = new DatePickerDialog(this, dpickerListener, year_x, month_x, day_x); dialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000); dialog.getDatePicker().setMaxDate(); As you can see, setMaxDate() is empty. I want to set the max date of the datePickerDialog to one month after the current date. Here's how I get the current date: cal2 = Calendar.getInstance(); currentDay = cal2.get(Calendar.DAY_OF_MONTH); currentMonth = cal2.get

Remaining days to a date is not showing correctly

大兔子大兔子 提交于 2019-12-12 18:37:48
问题 Ok, so I've created a function to show the number of days until a date in the future... It is correct until the amount of days is over 9 days.. if over it seems to show a random number of days... Please see my code below: public String daysTillExpire() { String daysLeft = ""; int position = 0 ; String inputDateString = UIDM.get(position).date; Calendar calCurr = Calendar.getInstance(); Calendar day = Calendar.getInstance(); try { day.setTime(new SimpleDateFormat("dd-MM-yyyy").parse

How to handle time zone difference between server and native android application?

*爱你&永不变心* 提交于 2019-12-12 08:24:09
问题 Suppose that my server located in USA and I live in Russia. We know that they have different time zones. My application getting text( String ) from server. And this text data has Date column in database to keep record date. When I get data, I also get date knowledge. So I can group them by time. First ones at the top and last ones at the bottom. Whatever... I wrote a function to show date value more human-readable such as "13 hours", "9 minutes". Server sends me the date in server's (USA)

How to show the time and date saved in my database to the user according to their local timezone? Please see details

前提是你 提交于 2019-12-12 03:02:25
问题 I'm developing an app in which I'm saving the date and time in Firebase and then retrieving it for the user to see. What I want is I want user to see that time and date according to their local timezone. for ex - if the time and date saved in database is '2:07 PM' and 'Fri, Jun 24', then to the users in PST timezone, it should be shown as '1:37 AM' and 'Fri, Jun 24'. Here's how I'm getting time and date: DateFormat currentTime = new SimpleDateFormat("h:mm a"); final String time = currentTime

how to determine whether the date of this week or last?

耗尽温柔 提交于 2019-12-12 01:22:40
问题 I have date array. For example 10 dates. I need calculate each date - it is this week or last week. How do make this? private List<Receipt> getSectionPosition(List<Receipt> receiptList){ List<Receipt> list = new ArrayList<>(); Date now = new Date(); for (int i = 0; i<receiptList.size(); i++){ if (receiptList.get(i).getCreatedDate().compareTo(now)==0){ list.add(receiptList.get(i)); } } return list; } i pass List<Receipt> and if receipt has date on this week i add it in new list. but it is not

How to format a date android?

社会主义新天地 提交于 2019-12-11 07:48:10
问题 I have a date in String an I using this: SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm"); dataUltima = sdf.format(sdf); to format the date. But this method return the actual date of system. How can I only format the date without change the date. Obs. I'm getting this date from a server, it come to me yyy-dd-MM and I want it dd/MM/yyyy 回答1: I am not sure what is your problem. Try it. Maybe help. String server_format = "2013-01-02"; //server comes format ? SimpleDateFormat sdf =

generate dates between two date in Android

梦想与她 提交于 2019-12-10 03:47:18
问题 How to get all dates between two dates in Android. For example. I have two Strings. String first="2012-07-15"; String second="2012-07-21"; I convert and get dates from these strings. DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd"); DateFormat df2 = new SimpleDateFormat("MMM dd"); String mydate = df2.format(df1.parse(first)); This way I get both dates from first and second String. Now I also display all dates between these two dates. 回答1: it is better not to use any hardcoded values in

Parse some string date to another format

为君一笑 提交于 2019-12-09 23:18:07
问题 I have problem formating date. From : EEE, d MMM yyyy HH:mm:ss Z (example : Mon, 05 Jan 2014 15:10:00 +0200) To : dd/MMM/yyyy HH:mm (example : 05/01/2014 15:10) Here is what i tried : private String formatDate(String date) { SimpleDateFormat format = new SimpleDateFormat("dd/MMM/yyyy HH:mm"); Date dateResult = null; try { dateResult = format.parse(date); } catch (java.text.ParseException e) { Log.e(TAG, "", e); } return dateResult.toString(); } I get exception : unparseable date at offset 0

Unknown pattern character 'x', when using SimpleDateFormat

回眸只為那壹抹淺笑 提交于 2019-12-09 17:50:00
问题 Im trying to format a Date to String using SimpleDateFormat , and the pattern im using is this one "yyyy-MM-dd'T'HH:mm:ss.SSSxxx" but when reach this line SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSxxx"); i get the following exception: java.lang.IllegalArgumentException: Unknown pattern character 'x' at java.text.SimpleDateFormat.validatePatternCharacter(SimpleDateFormat.java:323) at java.text.SimpleDateFormat.validatePattern(SimpleDateFormat.java:312) at java.text