Readdy Write

Android Java: Date

20.09.2018 (๐Ÿ‘2685)

Android Java: Date

 

Android Java: Date

 

How can I create a date and calculate the days of the week?

 

The current day can be obtained as a date variable with Date.

Date dtRow= new Date();

 

Format Date

A Date field can be output as string using the string formatting SimpleDateFormat

SimpleDateFormat fmtWeekday = new SimpleDateFormat("EE");
String weekday = fmtWeekday.format(dtRow);

 

If you want to be more complex with date, then you have to use the calendar.

To do this, create a calendar with Calendar.getInstance () and then assign a date to this calendar date.

If the date is assigned in the calendar, you can easily use Calendar.get (..) get the individual information about the calendar date.

//*as weekday_number
Calendar calendarDay=Calendar.getInstance();
calendarDay.setTime(dtRow);
int NrWeekday=calendarDay.get(Calendar.DAY_OF_WEEK);//  fmtWeekdayNr.format(dtRow);

 

 

 

Code example from the Android year calendar project, school calendar

//-< Date >-
Date dtRow= clsHelper.getDate(2018,9,iDay);
//< weekday >
//*as string
SimpleDateFormat fmtWeekday = new SimpleDateFormat("EE");
String weekday = fmtWeekday.format(dtRow);
//</ weekday >

//*as weekday_number
Calendar calendarDay=Calendar.getInstance();
calendarDay.setTime(dtRow);
int NrWeekday=calendarDay.get(Calendar.DAY_OF_WEEK);//  fmtWeekdayNr.format(dtRow);
//-</ Date >-

 


0,00 €