Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Android Java: Date

20.09.2018 (👁2656)

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 >-