Get first day of week - java routine

Two Stars

Get first day of week - java routine

Hi! I have a routine to generate week of year.
import java.util.Calendar;
import java.util.Date;

public class fechas {
public static String semana_del_anyo(Date date1) {
Calendar c1 = Calendar.getInstance();
c1.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
c1.setMinimalDaysInFirstWeek(1);
c1.setTime(date1);
int semana = c1.get(Calendar.WEEK_OF_YEAR);
if (semana < 10) {
return ( 0 + Integer.toString(semana));
} else {
return (Integer.toString(semana));
}}
}
Now, I need to set the first day of week as Monday because I suppose that it use the first day as Sunday. How can I include it in this routine?
Thank you
Regards
Community Manager

Re: Get first day of week - java routine

Dear user
The day of week starts with SunDay, if I understand you well, you can minus one day to the current date using the built-in function TalendDate.addDate(Date date, "-1","dd"), and then the get the day of week. For example, call your routine on a tJava component:
java.util.Date currentDate=TalendDate.getCurrentDate();
String day_of_week=fechas.semana_del_anyo(currentDate);
System.out.println(day_of_week);
java.util.Date date1=TalendDate.addDate(currentDate, "-1","dd");
String day_of_week1=fechas.semana_del_anyo(date1);
System.out.println(day_of_week1);
----------------------------------------------------------
Talend | Data Agility for Modern Business