How to display month name from DatePickerDialog - Android Studio
up vote
0
down vote
favorite
Hi I would like to display the month name when I click in my DatePickerDialog but it's display the month number
Here is my code
tvDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int day = calendar.get(Calendar.DAY_OF_WEEK);
int month = calendar.get(Calendar.MONTH);
int year = calendar.get(Calendar.YEAR);
dpd = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
}
}, year, month, day);
dpd.show();
}
});
java
add a comment |
up vote
0
down vote
favorite
Hi I would like to display the month name when I click in my DatePickerDialog but it's display the month number
Here is my code
tvDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int day = calendar.get(Calendar.DAY_OF_WEEK);
int month = calendar.get(Calendar.MONTH);
int year = calendar.get(Calendar.YEAR);
dpd = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
}
}, year, month, day);
dpd.show();
}
});
java
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Hi I would like to display the month name when I click in my DatePickerDialog but it's display the month number
Here is my code
tvDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int day = calendar.get(Calendar.DAY_OF_WEEK);
int month = calendar.get(Calendar.MONTH);
int year = calendar.get(Calendar.YEAR);
dpd = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
}
}, year, month, day);
dpd.show();
}
});
java
Hi I would like to display the month name when I click in my DatePickerDialog but it's display the month number
Here is my code
tvDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int day = calendar.get(Calendar.DAY_OF_WEEK);
int month = calendar.get(Calendar.MONTH);
int year = calendar.get(Calendar.YEAR);
dpd = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
}
}, year, month, day);
dpd.show();
}
});
java
java
asked Nov 11 at 15:27
Eduardo Noyola
435
435
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
You can format the date you get from DatePickerDialog to display the name of the month:
public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MMMM/yyyy");
calendar.set(nYear, nMonth, nDay);
String dateString = sdf.format(calendar.getTime());
tvDate.setText(dateString);
}
Thanks! This works for me!
– Eduardo Noyola
Nov 11 at 16:24
add a comment |
up vote
1
down vote
There are two ways of getting month name
Method 1
public static final String MONTHS = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
use an array and get the String by MONTHS[monthNumber].
Ref
Method 2
Setting the current date in the Calendar and getting back the month like this:
@Override
public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
calendar.set(Calendar.DAY_OF_MONTH,nDay);
calendar.set(Calendar.MONTH,nMonth);
calendar.set(Calendar.YEAR,mYear);
calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
}
In my personal opinion, I would recommend the Method 1
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You can format the date you get from DatePickerDialog to display the name of the month:
public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MMMM/yyyy");
calendar.set(nYear, nMonth, nDay);
String dateString = sdf.format(calendar.getTime());
tvDate.setText(dateString);
}
Thanks! This works for me!
– Eduardo Noyola
Nov 11 at 16:24
add a comment |
up vote
1
down vote
accepted
You can format the date you get from DatePickerDialog to display the name of the month:
public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MMMM/yyyy");
calendar.set(nYear, nMonth, nDay);
String dateString = sdf.format(calendar.getTime());
tvDate.setText(dateString);
}
Thanks! This works for me!
– Eduardo Noyola
Nov 11 at 16:24
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You can format the date you get from DatePickerDialog to display the name of the month:
public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MMMM/yyyy");
calendar.set(nYear, nMonth, nDay);
String dateString = sdf.format(calendar.getTime());
tvDate.setText(dateString);
}
You can format the date you get from DatePickerDialog to display the name of the month:
public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MMMM/yyyy");
calendar.set(nYear, nMonth, nDay);
String dateString = sdf.format(calendar.getTime());
tvDate.setText(dateString);
}
edited Nov 11 at 16:12
answered Nov 11 at 16:04
forpas
5,5431217
5,5431217
Thanks! This works for me!
– Eduardo Noyola
Nov 11 at 16:24
add a comment |
Thanks! This works for me!
– Eduardo Noyola
Nov 11 at 16:24
Thanks! This works for me!
– Eduardo Noyola
Nov 11 at 16:24
Thanks! This works for me!
– Eduardo Noyola
Nov 11 at 16:24
add a comment |
up vote
1
down vote
There are two ways of getting month name
Method 1
public static final String MONTHS = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
use an array and get the String by MONTHS[monthNumber].
Ref
Method 2
Setting the current date in the Calendar and getting back the month like this:
@Override
public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
calendar.set(Calendar.DAY_OF_MONTH,nDay);
calendar.set(Calendar.MONTH,nMonth);
calendar.set(Calendar.YEAR,mYear);
calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
}
In my personal opinion, I would recommend the Method 1
add a comment |
up vote
1
down vote
There are two ways of getting month name
Method 1
public static final String MONTHS = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
use an array and get the String by MONTHS[monthNumber].
Ref
Method 2
Setting the current date in the Calendar and getting back the month like this:
@Override
public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
calendar.set(Calendar.DAY_OF_MONTH,nDay);
calendar.set(Calendar.MONTH,nMonth);
calendar.set(Calendar.YEAR,mYear);
calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
}
In my personal opinion, I would recommend the Method 1
add a comment |
up vote
1
down vote
up vote
1
down vote
There are two ways of getting month name
Method 1
public static final String MONTHS = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
use an array and get the String by MONTHS[monthNumber].
Ref
Method 2
Setting the current date in the Calendar and getting back the month like this:
@Override
public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
calendar.set(Calendar.DAY_OF_MONTH,nDay);
calendar.set(Calendar.MONTH,nMonth);
calendar.set(Calendar.YEAR,mYear);
calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
}
In my personal opinion, I would recommend the Method 1
There are two ways of getting month name
Method 1
public static final String MONTHS = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
use an array and get the String by MONTHS[monthNumber].
Ref
Method 2
Setting the current date in the Calendar and getting back the month like this:
@Override
public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
calendar.set(Calendar.DAY_OF_MONTH,nDay);
calendar.set(Calendar.MONTH,nMonth);
calendar.set(Calendar.YEAR,mYear);
calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
}
In my personal opinion, I would recommend the Method 1
answered Nov 11 at 15:46
Burhanuddin Rashid
3,37852140
3,37852140
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250220%2fhow-to-display-month-name-from-datepickerdialog-android-studio%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown