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();
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
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);
java.util.Date date1=TalendDate.addDate(currentDate, "-1","dd");
String day_of_week1=fechas.semana_del_anyo(date1);
Talend | Data Agility for Modern Business