Android picker with full month name - android

I am trying to find a way to make the DatePicker which shows the year (number) the day of the month (number) and the Month as a 3 letters abbreviation to show the very same but with the full month name. I mean that I want it to let me choose between January, February... and not Jan, Feb...
Is there a way to do that?

try this code , in your date picker
Calendar mycalender = Calendar.getInstance();
mycalender.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault());

try this,
SimpleDateFormat format=new SimpleDateFormat("MMMM");// also you can use: "yyyy-MMMM-dd"
String monthName=format.format(Calendar.getInstance().getTime());

Related

CalendarView show minimum date as today

I want to show calendarView that will set the minimum date as today for booking purposes. But in my code it will show the whole month and here I can book the previous date. So, I need a solution that will show dates available from today and can not select previous days.
How can I do this?
My code:
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DATE,Calendar.getInstance().getActualMinimum(Calendar.DATE));
long date = calendar.getTime().getTime();
calendar_view.setMinDate(date);
Here is a solution. You need to set current date to the calendar minimum date.
Calendar calendar = Calendar.getInstance();
mCalendarView.setMinDate(calendar.getTimeInMillis());

change date format in datepicker dialog android

I have edit text field and I have a method that handles onclick event on edit field and show up a date picker dialog. However I want to change date format in the dialog . It shows Aug 31 2014, I like to show 31 08 2014. Is it possible?
This question has been answered elsewhere on the site, here for example. Basically the datepicker dialog shows up in the preferred format of the end user, so if they have their phone or emulator set to mm/dd/yyyy it will show up like that, if you want it to come up dd/mm/yyyy while you are testing it make sure your emulator is set up with that as the preferred date format.
In DatePickerDialog.OnDateSetListener you will get onDateSet method where you can get
int year = selectedYear;
int month = selectedMonth;
int day = selectedDay;
dateCalendar.set(Calendar.YEAR, year);
dateCalendar.set(Calendar.MONTH, month);
dateCalendar.set(Calendar.DAY_OF_MONTH, day);
String monthname = new SimpleDateFormat("MMM").format(dateCalendar.getTime());
in SimpleDateFormat you can change date format as you want

How to set a date in DatePicker

I want DatePicker shows a specific date when opened, unfortunately seems I can set only the date limits with setMinDate and setMaxDate.
Is there a way to set a date without block the selection with date limits?
DatePicker date = new DatePicker(context);
date.init(year, month, day, null);
where year, month and day are ints. Here is an explanation about init

how to display date format according to device time zone

I want to display date according to time zone... if its america than month date year and if its europe than date month year..it check the current date setting from device and convert current date and time according to time zone.
my code is
Time today = new Time(Time.getCurrentTimezone());
today.setToNow();
String currentDateandTime = today.monthDay+"/"+today.month+"/"+today.year+" "+today.hour+":"+today.minute;
can anybody suggest me some modification to have date organization according to time zone
Thank you in advance
You can use the DateFormat class.
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG,Locale.FRANCE);
To get the users current Locale you can do
Locale.getDefault();
Be warned though it might not be what the user wants.

Calendar dayOfMonth off by 1

When trying to get a string for the current date using
DateFormat.getDateInstance().format(calendar.getTime())
it keeps returning the wrong day. For example, it is saying today, July 25th., is July 26th. Also when I use it to sat a date picker, I get the day value by using
dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
When the date picker is set, it also shows the day ahead by 1.
To get the calendar I'm using
Calendar calendar = Calendar.getInstance();
Is there something I'm missing?
Thanks
I would imagine this is because you havent set the timezone to your timezone, and rather than the day being off randomly, the time zone you are in is diferent than GMT (Greenwich Median? Time). Try looking at this example How to handle calendar TimeZones using Java?

Categories

Resources