Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

COMMANDE "CAL" SOUS *UX


Information sur la source

Description

Cliquez pour voir la capture en taille normale
Je sais : Ca existe depuis toujours sous *Ux...
Mais, malheureux consultant que je suis, je dois utiliser le même OS que le client...
Comme j'ai viré l'horloge de la "StartBar" et que j'ai toujours un shell. "Pardon!" Un "command prompt" ouvert.
J'ai fait une petite recherche pour trouver l'équivalent de cal en Wintendo... Après la première page, je me suis dit : Pourquoi pas le coder? J'ai donc vite codé ça sur l'heure de table(une grosse heure de table). ;-)

En clair: Ce que fait le programme :
Il affiche le calendrier de l'année demandée sinon l'année courante.
Les strings, ["chaines de caractères"], sont tirés de la local du PC. Ca veut dire que si votre PC et configuré English, ce sera January, February,... Et Mo, Tu ...
Ho! Il affiche un petit "<" après la date du jour.

Ce code n'a rien d'exceptionnel, mais si ça peut aider l'un ou l'autre...

PS: Dans le zip, j'ai packagé en Jar, contenant un MANIFEST.MF pour que la class soit exécuté toute seule.
----------------------------
MANIFEST.MF
----------------------------
Manifest-Version: 1.0
Main-Class: be.dje.tools.Cal
----------------------------
Ainsi qu'un cal.bat pour ceux qui n'aurait déjà(comme moi) une association .jar vers "7Zip".
 

Source

  • package be.dje.tools;
  • import java.text.DateFormat;
  • import java.text.SimpleDateFormat;
  • import java.util.Calendar;
  • import java.util.Date;
  • import java.util.GregorianCalendar;
  • import java.util.TimeZone;
  • import java.util.Vector;
  • public class Cal
  • {
  • static String semyear[][][]=new String [13][6][8];
  • /**
  • * @param args
  • */
  • public static void main(String[] args)
  • {
  • int annee=0;
  • int dayofweek=0;
  • int weekofmonth=0;
  • int month=0;
  • int index=0;
  • Vector vDayNames=new Vector();
  • Vector vMonthNames=new Vector();
  • String MonthTitle="";
  • Date dt1;
  • try
  • {
  • Calendar epoch = GregorianCalendar.getInstance(TimeZone.getDefault());//TimeZone.getTimeZone("Europe/Paris"));
  • if (args.length!=0) annee=Integer.parseInt(args[0]);
  • else annee=epoch.get(Calendar.YEAR);
  • //init table
  • for(int i=0;i<13;i++)
  • for (int j=0;j<6;j++)
  • for (int k=0;k<8;k++) semyear[i][j][k]=" ";
  • System.out.println(annee);
  • //Set epoch to 1st jan of the year
  • dt1 = stringToDate("01/01/"+annee,"dd/MM/yyyy");
  • epoch.setTime(dt1);
  • //fill the vector vDayNames with short names of days of the week
  • DateFormat dateFormat = new SimpleDateFormat("EEE");
  • index=1;//sunday 1st
  • while (index<8)
  • {
  • if (epoch.get(Calendar.DAY_OF_WEEK)==index)
  • {
  • vDayNames.add(dateFormat.format(epoch.getTime()));
  • index++;
  • }
  • epoch.add(Calendar.DAY_OF_YEAR, 1);//while epoch isn't a sunday
  • }
  • //re initialize to 1st jan of the year
  • dt1 = stringToDate("01/01/"+annee,"dd/MM/yyyy");
  • epoch.setTime(dt1);
  • //fill the vector vMonthNames with full month names
  • dateFormat = new SimpleDateFormat("MMMMM");
  • index=Calendar.JANUARY;
  • while (index<=Calendar.DECEMBER)
  • {
  • vMonthNames.add(dateFormat.format(epoch.getTime()));
  • index++;
  • epoch.add(Calendar.MONTH, 1);
  • }
  • //re initialize to 1st jan of the year
  • dt1 = stringToDate("01/01/"+annee,"dd/MM/yyyy");
  • epoch.setTime(dt1);
  • //fill the table of the current year
  • while (epoch.get(Calendar.YEAR)==annee)
  • {
  • dayofweek=epoch.get(Calendar.DAY_OF_WEEK);
  • weekofmonth=epoch.get(Calendar.WEEK_OF_MONTH);
  • month=epoch.get(Calendar.MONTH);
  • if (epoch.get(Calendar.DAY_OF_MONTH)<10)
  • semyear[month][weekofmonth][dayofweek]="0"+Integer.toString(epoch.get(Calendar.DAY_OF_MONTH));
  • else
  • semyear[month][weekofmonth][dayofweek]=Integer.toString(epoch.get(Calendar.DAY_OF_MONTH));
  • epoch.add(Calendar.DAY_OF_YEAR, 1);
  • }
  • //Cycle for Lines of months
  • for (int monthboucle=0;monthboucle<3;monthboucle++)
  • {
  • epoch = GregorianCalendar.getInstance(TimeZone.getDefault());
  • //*************************************************************************************
  • //Print month names
  • MonthTitle=((String)vMonthNames.get(0+monthboucle*4));
  • for(int i=MonthTitle.length();i<22;i++) MonthTitle+=" ";//up to char pos 22
  • MonthTitle+=((String)vMonthNames.get(1+monthboucle*4));
  • for(int i=MonthTitle.length();i<44;i++) MonthTitle+=" ";//up to char pos 44
  • MonthTitle+=((String)vMonthNames.get(2+monthboucle*4));
  • for(int i=MonthTitle.length();i<66;i++) MonthTitle+=" ";//up to char pos 66
  • MonthTitle+=((String)vMonthNames.get(3+monthboucle*4));
  • System.out.println(MonthTitle);
  • //Show days name
  • for (int i=0;i<4;i++)
  • {
  • for (int j=epoch.getFirstDayOfWeek()-1;j<7;j++)
  • System.out.print(((String)vDayNames.get(j)).substring(0, 2)+" ");
  • if (epoch.getFirstDayOfWeek()>1)
  • for (int j=0;j<epoch.getFirstDayOfWeek()-1;j++)
  • System.out.print(((String)vDayNames.get(j)).substring(0, 2)+" ");
  • System.out.print(" ");
  • }
  • System.out.println("");
  • //print a line of months
  • for (weekofmonth=0;weekofmonth<6;weekofmonth++)//6 lines per months
  • {
  • for (month=0;month<4;month++) //4 months per line
  • {
  • for (int day=epoch.getFirstDayOfWeek();day<8;day++) //7 days per week
  • {
  • System.out.print(semyear[month+monthboucle*4][weekofmonth][day]);
  • if ((annee==epoch.get(Calendar.YEAR))&& //test to put a "<" after the current day
  • ((month+monthboucle*4)==epoch.get(Calendar.MONTH))&&
  • (!semyear[month+monthboucle*4][weekofmonth][day].trim().isEmpty())&&
  • ( Integer.parseInt(semyear[month+monthboucle*4][weekofmonth][day].trim())==epoch.get(Calendar.DAY_OF_MONTH)) )
  • System.out.print("<");
  • else System.out.print(" ");
  • }
  • if (epoch.getFirstDayOfWeek()>1)
  • for (int day=1;day<epoch.getFirstDayOfWeek();day++)
  • {
  • System.out.print(semyear[month+monthboucle*4][weekofmonth][day]);
  • if ((annee==epoch.get(Calendar.YEAR))&& //test to put a "<" after the current day
  • ((month+monthboucle*4)==epoch.get(Calendar.MONTH))&&
  • (!semyear[month+monthboucle*4][weekofmonth][day].trim().isEmpty())&&
  • ( Integer.parseInt(semyear[month+monthboucle*4][weekofmonth][day].trim())==epoch.get(Calendar.DAY_OF_MONTH)) )
  • System.out.print("<"); else System.out.print(" ");
  • }
  • System.out.print(" ");//split to next month on the same line
  • }
  • System.out.println("");// New line after week printed for 4 months
  • }
  • System.out.println(""); //new line after the "Months line"
  • //*************************************************************************************
  • }//endfor
  • } catch (Exception e)
  • {
  • e.printStackTrace();
  • }
  • }
  • public static Date stringToDate(String sDate, String sFormat) throws Exception
  • {
  • SimpleDateFormat sdf = new SimpleDateFormat(sFormat);
  • return sdf.parse(sDate);
  • }
  • }
package be.dje.tools;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import java.util.Vector;

public class Cal 
{
	static String semyear[][][]=new String [13][6][8];

	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		int annee=0;
		int dayofweek=0;
		int weekofmonth=0;
		int month=0;
		int index=0;
		Vector vDayNames=new Vector();
		Vector vMonthNames=new Vector();
		String MonthTitle="";
		
		Date dt1;
		try 
		{
			Calendar epoch = GregorianCalendar.getInstance(TimeZone.getDefault());//TimeZone.getTimeZone("Europe/Paris"));
			if (args.length!=0) annee=Integer.parseInt(args[0]);
			else annee=epoch.get(Calendar.YEAR);
			
			//init table
			for(int i=0;i<13;i++)
				for (int j=0;j<6;j++)
					for (int k=0;k<8;k++) semyear[i][j][k]="  ";
			
			System.out.println(annee);
			
			//Set epoch to 1st jan of the year
			dt1 = stringToDate("01/01/"+annee,"dd/MM/yyyy");
			epoch.setTime(dt1);
			
			//fill the vector vDayNames with short names of days of the week
			DateFormat dateFormat = new SimpleDateFormat("EEE");
			index=1;//sunday 1st
			while (index<8)
			{
				if (epoch.get(Calendar.DAY_OF_WEEK)==index)	
					{
						vDayNames.add(dateFormat.format(epoch.getTime()));
						index++;
					}
				epoch.add(Calendar.DAY_OF_YEAR, 1);//while epoch isn't a sunday
			}
			
			//re initialize to 1st jan of the year
			dt1 = stringToDate("01/01/"+annee,"dd/MM/yyyy");
			epoch.setTime(dt1);
			
			//fill the vector vMonthNames with full month names
			dateFormat = new SimpleDateFormat("MMMMM");
			index=Calendar.JANUARY;
			while (index<=Calendar.DECEMBER)
			{
				vMonthNames.add(dateFormat.format(epoch.getTime()));
				index++;
				epoch.add(Calendar.MONTH, 1);
			}

			//re initialize to 1st jan of the year
			dt1 = stringToDate("01/01/"+annee,"dd/MM/yyyy");
			epoch.setTime(dt1);
			
			//fill the table of the current year
			while (epoch.get(Calendar.YEAR)==annee)
			{
				dayofweek=epoch.get(Calendar.DAY_OF_WEEK);
				weekofmonth=epoch.get(Calendar.WEEK_OF_MONTH);
				month=epoch.get(Calendar.MONTH);
				if (epoch.get(Calendar.DAY_OF_MONTH)<10)
					semyear[month][weekofmonth][dayofweek]="0"+Integer.toString(epoch.get(Calendar.DAY_OF_MONTH));
				else
					semyear[month][weekofmonth][dayofweek]=Integer.toString(epoch.get(Calendar.DAY_OF_MONTH));
				epoch.add(Calendar.DAY_OF_YEAR, 1);
			}
			
			//Cycle for Lines of months
			for (int monthboucle=0;monthboucle<3;monthboucle++)
			{
				epoch = GregorianCalendar.getInstance(TimeZone.getDefault());
				//*************************************************************************************
				//Print month names
				MonthTitle=((String)vMonthNames.get(0+monthboucle*4));
				for(int i=MonthTitle.length();i<22;i++) MonthTitle+=" ";//up to char pos 22
				MonthTitle+=((String)vMonthNames.get(1+monthboucle*4));
				for(int i=MonthTitle.length();i<44;i++) MonthTitle+=" ";//up to char pos 44
				MonthTitle+=((String)vMonthNames.get(2+monthboucle*4));
				for(int i=MonthTitle.length();i<66;i++) MonthTitle+=" ";//up to char pos 66
				MonthTitle+=((String)vMonthNames.get(3+monthboucle*4));
				System.out.println(MonthTitle);
				
				//Show days name
				for (int i=0;i<4;i++)
				{
					for (int j=epoch.getFirstDayOfWeek()-1;j<7;j++)
						System.out.print(((String)vDayNames.get(j)).substring(0, 2)+" ");
					if (epoch.getFirstDayOfWeek()>1)
						for (int j=0;j<epoch.getFirstDayOfWeek()-1;j++)
							System.out.print(((String)vDayNames.get(j)).substring(0, 2)+" ");
					System.out.print(" ");
				}		
				System.out.println("");
				
				//print a line of months
				for (weekofmonth=0;weekofmonth<6;weekofmonth++)//6 lines per months
				{
					for (month=0;month<4;month++) //4 months per line
					{
						for (int day=epoch.getFirstDayOfWeek();day<8;day++) //7 days per week
						{
							System.out.print(semyear[month+monthboucle*4][weekofmonth][day]);
							if ((annee==epoch.get(Calendar.YEAR))&& //test to put a "<" after the current day
									((month+monthboucle*4)==epoch.get(Calendar.MONTH))&&
									(!semyear[month+monthboucle*4][weekofmonth][day].trim().isEmpty())&&
									( Integer.parseInt(semyear[month+monthboucle*4][weekofmonth][day].trim())==epoch.get(Calendar.DAY_OF_MONTH)) ) 
								System.out.print("<"); 
							else System.out.print(" ");
						}
						if (epoch.getFirstDayOfWeek()>1)
							for (int day=1;day<epoch.getFirstDayOfWeek();day++)
							{
								System.out.print(semyear[month+monthboucle*4][weekofmonth][day]);
								if ((annee==epoch.get(Calendar.YEAR))&& //test to put a "<" after the current day
										((month+monthboucle*4)==epoch.get(Calendar.MONTH))&&
										(!semyear[month+monthboucle*4][weekofmonth][day].trim().isEmpty())&&
										( Integer.parseInt(semyear[month+monthboucle*4][weekofmonth][day].trim())==epoch.get(Calendar.DAY_OF_MONTH)) ) 
									System.out.print("<"); else System.out.print(" ");
							}
						System.out.print(" ");//split to next month on the same line
					}
					System.out.println("");// New line after week printed for 4 months
	
				}
				System.out.println(""); //new line after the "Months line"
				//*************************************************************************************
			}//endfor 
		} catch (Exception e) 
		{
			e.printStackTrace();
		}


	}
	
    public static Date stringToDate(String sDate, String sFormat) throws Exception 
    {
        SimpleDateFormat sdf = new SimpleDateFormat(sFormat);
        return sdf.parse(sDate);
    }

}

Conclusion

Tite remarque : J'ai pas blindé la lecture param. Si on s'ammuse à mettre autre chose qu'une valeur du type année, ça va petter en exception...
 

Fichier Zip

Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  • cal.zipTélécharger ce fichier [Réservé aux membres club]2 821 octets
  • calSRC.zipTélécharger ce fichier [Réservé aux membres club]5 184 octets

Télécharger le zip

Commentaires et avis

signaler à un administrateur
Commentaire de Twinuts le 19/09/2007 20:03:37 administrateur CS

Salut,

je n'ai pas testé, ni regardé le code mais d'après la capture, l'appli me bote bien (même si j'ai déjà cal) ^^.

Si tu veux faire comme cal tu peux regarder du coté de ma source (http://www.javafr.com/codes/ECRIRE-COULEURS-SUR-CONSOLE-JNI_39674.aspx) pour modifier le fond du bon jour ^^

le code tourne sous nux et windoz (normalement mac, mais je n'ai pas de ppc avec un mac os...).

signaler à un administrateur
Commentaire de yvkoe le 20/09/2007 14:01:22

Bonjour,
j'ai mis ton appli dans Eclipse et voila ce que ca donne
t'aurais pas oublié quelques petites choses (isEmpty??,formatDate??)


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar; import java.util.TimeZone;
import java.util.Vector;

public class Cal
{
static String semyear[][][]=new String [13][6][

public static void main(String[] args)
{
int annee=0;
int dayofweek=0;
int weekofmonth=0;
int month=0; int index=0;
Vector vDayNames=new Vector();
Vector vMonthNames=new Vector();
String MonthTitle="";

Date dt1;
try
{
Calendar epoch = GregorianCalendar.getInstance(TimeZone.getDefault());//TimeZone.getTimeZone("Europe/Paris"));
if (args.length!=0) annee=Integer.parseInt(args[0]);
else annee=epoch.get(Calendar.YEAR);

//init table for(int i=0;i<13;i++)
for (int j=0;j<6;j++)
for (int k=0;k<8;k++) semyear[i][j][k]=" ";

System.out.println(annee);

//Set epoch to 1st jan of the year
dt1 = stringToDate("01/01/"+annee,"dd/MM/yyyy");
epoch.setTime(dt1);

//fill the vector vDayNames with short names of days of the weekDateFormat dateFormat = new SimpleDateFormat("EEE");
index=1;//sunday 1st
while (index<8)
{
if (epoch.get(Calendar.DAY_OF_WEEK)==index)
{
vDayNames.add(DateFormat.format(epoch.getTime()));
index++;
}
epoch.add(Calendar.DAY_OF_YEAR, 1);//while epoch isn't a sunday
}

//re initialize to 1st jan of the year
dt1 = stringToDate("01/01/"+annee,"dd/MM/yyyy");
epoch.setTime(dt1);

//fill the vector vMonthNames with full month names
DateFormat = new SimpleDateFormat("MMMMM");
index=Calendar.JANUARY;
while (index<=Calendar.DECEMBER)
{
vMonthNames.add(DateFormat.format(epoch.getTime()));
index++;
epoch.add(Calendar.MONTH, 1);
}

//re initialize to 1st jan of the year
dt1 = stringToDate("01/01/"+annee,"dd/MM/yyyy");
epoch.setTime(dt1);

//fill the table of the current year
while (epoch.get(Calendar.YEAR)==annee)
{
dayofweek=epoch.get(Calendar.DAY_OF_WEEK);
weekofmonth=epoch.get(Calendar.WEEK_OF_MONTH);
month=epoch.get(Calendar.MONTH);
if (epoch.get(Calendar.DAY_OF_MONTH)<10)
semyear[month][weekofmonth][dayofweek]="0"+Integer.toString(epoch.get(Calendar.DAY_OF_MONTH));
else
semyear[month][weekofmonth][dayofweek]=Integer.toString(epoch.get(Calendar.DAY_OF_MONTH));
epoch.add(Calendar.DAY_OF_YEAR, 1);
}
//Cycle for Lines of months
for (int monthboucle=0;monthboucle<3;monthboucle++)
{
epoch = GregorianCalendar.getInstance(TimeZone.getDefault());
//*************************************************************************************
//Print month names
MonthTitle=((String)vMonthNames.get(0+monthboucle*4));
for(int i=MonthTitle.length();i<22;i++) MonthTitle+=" ";//up to char pos 22
MonthTitle+=((String)vMonthNames.get(1+monthboucle*4));
for(int i=MonthTitle.length();i<44;i++) MonthTitle+=" ";//up to char pos 44
MonthTitle+=((String)vMonthNames.get(2+monthboucle*4));
for(int i=MonthTitle.length();i<66;i++) MonthTitle+=" ";//up to char pos 66
MonthTitle+=((String)vMonthNames.get(3+monthboucle*4));
System.out.println(MonthTitle);

//Show days name
for (int i=0;i<4;i++)
{
for (int j=epoch.getFirstDayOfWeek()-1;j<7;j++)
System.out.print(((String)vDayNames.get(j)).substring(0, 2)+" ");
if (epoch.getFirstDayOfWeek()>1)
for (int j=0;j<epoch.getFirstDayOfWeek()-1;j++)
System.out.print(((String)vDayNames.get(j)).substring(0, 2)+" ");
System.out.print(" ");
}
System.out.println("");

//print a line of months
for (weekofmonth=0;weekofmonth<6;weekofmonth++)//6 lines per months
{
for (month=0;month<4;month++) //4 months per line
{
for (int day=epoch.getFirstDayOfWeek();day<8;day++) //7 days per week
{
System.out.print(semyear[month+monthboucle*4][weekofmonth][day]);
if ((annee==epoch.get(Calendar.YEAR))&& //test to put a "<" after the current day
((month+monthboucle*4)==epoch.get(Calendar.MONTH))&&
(!semyear[month+monthboucle*4][weekofmonth][day].trim().isEmpty())&&
( Integer.parseInt(semyear[month+monthboucle*4][weekofmonth][day].trim())==epoch.get(Calendar.DAY_OF_MONTH)) )
System.out.print("<");
else System.out.print(" ");
}
if (epoch.getFirstDayOfWeek()>1)
for (int day=1;day<epoch.getFirstDayOfWeek();day++)
{
System.out.print(semyear[month+monthboucle*4][weekofmonth][day]);
if ((annee==epoch.get(Calendar.YEAR))&& //test to put a "<" after the current day
((month+monthboucle*4)==epoch.get(Calendar.MONTH))&&
(!semyear[month+monthboucle*4][weekofmonth][day].trim().isEmpty())&&
( Integer.parseInt(semyear[month+monthboucle*4][weekofmonth][day].trim())==epoch.get(Calendar.DAY_OF_MONTH)) )
System.out.print("<"); else System.out.print(" ");
}
System.out.print(" ");//split to next month on the same line
}
System.out.println("");// New line after week printed for 4 months

}
System.out.println(""); //new line after the "Months line"
//*************************************************************************************
}//endfor
} catch (Exception e)
{
e.printStackTrace();
# }
#
#
# }
#
public static Date stringToDate(String sDate, String sFormat) throws Exception
{
SimpleDateFormat sdf = new SimpleDateFormat(sFormat);
return sdf.parse(sDate);
}

}

signaler à un administrateur
Commentaire de yvkoe le 20/09/2007 14:08:45

Rebonjour,
soit je ne sais plus faire un copier coller,soit Eclipse a peté un boulo, soit ton package (que j'ai viré puisque je ne l'ai pas) contenait les codes manquants )
mais si c'est sur ton heure de table...tu es pardonné
Beau boulot en si peu de temps

signaler à un administrateur
Commentaire de Twinuts le 20/09/2007 21:02:42 administrateur CS

Salut,

yvkoe > Si ce que tu as mit 2 poste plus haut, c'est ce que tu as mit dans eclipse, regarde vers le bas il y a encore des #
[...]
{
e.printStackTrace();
# }
#
#
# }
#
public static Date stringToDate(String sDate, String sFormat) throws Exception
{
[...]
pour le reste tu as du faire des choses hors sujet avec ton eclipse et le code ....
voici le code sans les # :
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import java.util.Vector;

public class Cal {
static String semyear[][][] = new String[13][6][8];

/**
* @param args
*/
public static void main(String[] args) {
int annee = 0;
int dayofweek = 0;
int weekofmonth = 0;
int month = 0;
int index = 0;
Vector vDayNames = new Vector();
Vector vMonthNames = new Vector();
String MonthTitle = "";

Date dt1;
try {
Calendar epoch = GregorianCalendar.getInstance(TimeZone
.getDefault());// TimeZone.getTimeZone("Europe/Paris"));
if (args.length != 0)
annee = Integer.parseInt(args[0]);
else
annee = epoch.get(Calendar.YEAR);

// init table
for (int i = 0; i < 13; i++)
for (int j = 0; j < 6; j++)
for (int k = 0; k < 8; k++)
semyear[i][j][k] = " ";

System.out.println(annee);

// Set epoch to 1st jan of the year
dt1 = stringToDate("01/01/" + annee, "dd/MM/yyyy");
epoch.setTime(dt1);

// fill the vector vDayNames with short names of days of the week
DateFormat dateFormat = new SimpleDateFormat("EEE");
index = 1;// sunday 1st
while (index < 8) {
if (epoch.get(Calendar.DAY_OF_WEEK) == index) {
vDayNames.add(dateFormat.format(epoch.getTime()));
index++;
}
epoch.add(Calendar.DAY_OF_YEAR, 1);// while epoch isn't a
// sunday
}

// re initialize to 1st jan of the year
dt1 = stringToDate("01/01/" + annee, "dd/MM/yyyy");
epoch.setTime(dt1);

// fill the vector vMonthNames with full month names
dateFormat = new SimpleDateFormat("MMMMM");
index = Calendar.JANUARY;
while (index <= Calendar.DECEMBER) {
vMonthNames.add(dateFormat.format(epoch.getTime()));
index++;
epoch.add(Calendar.MONTH, 1);
}

// re initialize to 1st jan of the year
dt1 = stringToDate("01/01/" + annee, "dd/MM/yyyy");
epoch.setTime(dt1);

// fill the table of the current year
while (epoch.get(Calendar.YEAR) == annee) {
dayofweek = epoch.get(Calendar.DAY_OF_WEEK);
weekofmonth = epoch.get(Calendar.WEEK_OF_MONTH);
month = epoch.get(Calendar.MONTH);
if (epoch.get(Calendar.DAY_OF_MONTH) < 10)
semyear[month][weekofmonth][dayofweek] = "0"
+ Integer
.toString(epoch.get(Calendar.DAY_OF_MONTH));
else
semyear[month][weekofmonth][dayofweek] = Integer
.toString(epoch.get(Calendar.DAY_OF_MONTH));
epoch.add(Calendar.DAY_OF_YEAR, 1);
}

// Cycle for Lines of months
for (int monthboucle = 0; monthboucle < 3; monthboucle++) {
epoch = GregorianCalendar.getInstance(TimeZone.getDefault());
// *************************************************************************************
// Print month names
MonthTitle = ((String) vMonthNames.get(0 + monthboucle * 4));
for (int i = MonthTitle.length(); i < 22; i++)
MonthTitle += " ";// up to char pos 22
MonthTitle += ((String) vMonthNames.get(1 + monthboucle * 4));
for (int i = MonthTitle.length(); i < 44; i++)
MonthTitle += " ";// up to char pos 44
MonthTitle += ((String) vMonthNames.get(2 + monthboucle * 4));
for (int i = MonthTitle.length(); i < 66; i++)
MonthTitle += " ";// up to char pos 66
MonthTitle += ((String) vMonthNames.get(3 + monthboucle * 4));
System.out.println(MonthTitle);

// Show days name
for (int i = 0; i < 4; i++) {
for (int j = epoch.getFirstDayOfWeek() - 1; j < 7; j++)
System.out.print(((String) vDayNames.get(j)).substring(
0, 2)
+ " ");
if (epoch.getFirstDayOfWeek() > 1)
for (int j = 0; j < epoch.getFirstDayOfWeek() - 1; j++)
System.out.print(((String) vDayNames.get(j))
.substring(0, 2)
+ " ");
System.out.print(" ");
}
System.out.println("");

// print a line of months
for (weekofmonth = 0; weekofmonth < 6; weekofmonth++)// 6
// lines
// per
// months
{
for (month = 0; month < 4; month++) // 4 months per line
{
for (int day = epoch.getFirstDayOfWeek(); day < 8; day++) // 7
// days
// per
// week
{
System.out
.print(semyear[month + monthboucle * 4][weekofmonth][day]);
if ((annee == epoch.get(Calendar.YEAR))
&& // test to put a "<" after the current
// day
((month + monthboucle * 4) == epoch
.get(Calendar.MONTH))
&& (!semyear[month + monthboucle * 4][weekofmonth][day]
.trim().isEmpty())
&& (Integer
.parseInt(semyear[month
+ monthboucle * 4][weekofmonth][day]
.trim()) == epoch
.get(Calendar.DAY_OF_MONTH)))
System.out.print("<");
else
System.out.print(" ");
}
if (epoch.getFirstDayOfWeek() > 1)
for (int day = 1; day < epoch.getFirstDayOfWeek(); day++) {
System.out.print(semyear[month + monthboucle
* 4][weekofmonth][day]);
if ((annee == epoch.get(Calendar.YEAR))
&& // test to put a "<" after the
// current day
((month + monthboucle * 4) == epoch
.get(Calendar.MONTH))
&& (!semyear[month + monthboucle * 4][weekofmonth][day]
.trim().isEmpty())
&& (Integer
.parseInt(semyear[month
+ monthboucle * 4][weekofmonth][day]
.trim()) == epoch
.get(Calendar.DAY_OF_MONTH)))
System.out.print("<");
else
System.out.print(" ");
}
System.out.print(" ");// split to next month on the
// same line
}
System.out.println("");// New line after week printed for 4
// months

}
System.out.println(""); // new line after the "Months line"
// *************************************************************************************
}// endfor
} catch (Exception e) {
e.printStackTrace();
}

}

public static Date stringToDate(String sDate, String sFormat)
throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat(sFormat);
return sdf.parse(sDate);
}

}

signaler à un administrateur
Commentaire de yvkoe le 22/09/2007 12:55:43

bonjour,
voici après compil le message eclipseException in thread "main" java.lang.Error: Problèmes de compilation non résolus :
La méthode isEmpty() est indéfinie pour le type String
La méthode isEmpty() est indéfinie pour le type String

at Cal.main(cal.java:147)
Désole mais la c'est eclipse

signaler à un administrateur
Commentaire de dje_jay le 24/09/2007 14:05:21

Bonjour,

Merci de vos réactions.
Yvkoe : As-tu récupéré le projet du zip ou c'est le résultat d'un copy/past?
A la ligne 147, j'ai "}", le dernier "isEmpty" est à la ligne 139...
D'autre part, est-ce que tu utilises un JDK récent?
Je ne saurais dire à partir de quand est apparue la méthode isEmpty, mais le JDK1.5 l'a...
----------------------
boolean isEmpty()
          Returns true if, and only if, length() is 0.
----------------------
(J'utilise Eclipse 3.2)

signaler à un administrateur
Commentaire de yvkoe le 24/09/2007 14:47:19

bonjour,
eh oui j'ai JDK 1.5 et eclipse dernière version(mise à jour automatique à l'ouverture)
j'ai fait un copy past ,essaye avec eclipse et copy paste sur la version ci dessus ,crois moi je préfèrerais ne pas avoir d'erreur car je trouve le cal très sympa...

signaler à un administrateur
Commentaire de dje_jay le 24/09/2007 17:39:55

Bon ... Ben ok! :-p lol!
"isEmpty" est apparu à partir du JDK 1.6 ...
(Mon JDK par defaut n'est pas celui que je pensais)...
Vous pouvez remplacer "isEmpty" par ".length()!=0" (En effaçant le "!" du début de condition). Ca donne :
...
(semyear[month+monthboucle*4][weekofmonth][day].trim().length()!=0)&&
...

signaler à un administrateur
Commentaire de yvkoe le 25/09/2007 11:26:36

bonjour,
bravo là pas de blème tout fonctionne bravo encore

signaler à un administrateur
Commentaire de yvkoe le 25/09/2007 11:46:55

Au secours !
voila ce que cela donne une fois comilé et executé:
2007
janvier               février               mars                  avril
lu ma me je ve sa di  lu ma me je ve sa di  lu ma me je ve sa di  lu ma me je ve sa di  
                                                         01  
01 02 03 04 05 06 07        01 02 03 04        01 02 03 04  02 03 04 05 06 07 08  
08 09 10 11 12 13 14  05 06 07 08 09 10 11  05 06 07 08 09 10 11  09 10 11 12 13 14 15  
15 16 17 18 19 20 21  12 13 14 15 16 17 18  12 13 14 15 16 17 18  16 17 18 19 20 21 22  
22 23 24 25 26 27 28  19 20 21 22 23 24 25  19 20 21 22 23 24 25  23 24 25 26 27 28 29  
29 30 31          26 27 28          26 27 28 29 30 31    30              

mai                   juin                  juillet               août
lu ma me je ve sa di  lu ma me je ve sa di  lu ma me je ve sa di  lu ma me je ve sa di  
                       01 02 03              01                
  01 02 03 04 05 06  04 05 06 07 08 09 10  02 03 04 05 06 07 08      01 02 03 04 05  
07 08 09 10 11 12 13  11 12 13 14 15 16 17  09 10 11 12 13 14 15  06 07 08 09 10 11 12  
14 15 16 17 18 19 20  18 19 20 21 22 23 24  16 17 18 19 20 21 22  13 14 15 16 17 18 19  
21 22 23 24 25 26 27  25 26 27 28 29 30    23 24 25 26 27 28 29  20 21 22 23 24 25 26  
28 29 30 31                       30 31            27 28 29 30 31      

septembre             octobre               novembre              décembre
lu ma me je ve sa di  lu ma me je ve sa di  lu ma me je ve sa di  lu ma me je ve sa di  
          01 02                                          01 02  
03 04 05 06 07 08 09  01 02 03 04 05 06 07        01 02 03 04  03 04 05 06 07 08 09  
10 11 12 13 14 15 16  08 09 10 11 12 13 14  05 06 07 08 09 10 11  10 11 12 13 14 15 16  
17 18 19 20 21 22 23  15 16 17 18 19 20 21  12 13 14 15 16 17 18  17 18 19 20 21 22 23  
24 25<26 27 28 29 30  22 23 24 25 26 27 28  19 20 21 22 23 24 25  24 25 26 27 28 29 30  
               29 30 31          26 27 28 29 30      31              
C'st un petit peu décalé...
voila le code une fois les modif exécutée:

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import java.util.Vector;

public class Cal {
static String semyear[][][] = new String[13][6][8];

/**
* @param args
*/
public static void main(String[] args) {
int annee = 0;
int dayofweek = 0;
int weekofmonth = 0;
int month = 0;
int index = 0;
Vector vDayNames = new Vector();
Vector vMonthNames = new Vector();
String MonthTitle = "";

Date dt1;
try {
Calendar epoch = GregorianCalendar.getInstance(TimeZone
.getDefault());// TimeZone.getTimeZone("Europe/Paris"));
if (args.length != 0)
annee = Integer.parseInt(args[0]);
else
annee = epoch.get(Calendar.YEAR);

// init table
for (int i = 0; i < 13; i++)
for (int j = 0; j < 6; j++)
for (int k = 0; k < 8; k++)
semyear[i][j][k] = " ";

System.out.println(annee);

// Set epoch to 1st jan of the year
dt1 = stringToDate("01/01/" + annee, "dd/MM/yyyy");
epoch.setTime(dt1);

// fill the vector vDayNames with short names of days of the week
DateFormat dateFormat = new SimpleDateFormat("EEE");
index = 1;// sunday 1st
while (index < 8) {
if (epoch.get(Calendar.DAY_OF_WEEK) == index) {
vDayNames.add(dateFormat.format(epoch.getTime()));
index++;
}
epoch.add(Calendar.DAY_OF_YEAR, 1);// while epoch isn't a
// sunday
}

// re initialize to 1st jan of the year
dt1 = stringToDate("01/01/" + annee, "dd/MM/yyyy");
epoch.setTime(dt1);

// fill the vector vMonthNames with full month names
dateFormat = new SimpleDateFormat("MMMMM");
index = Calendar.JANUARY;
while (index <= Calendar.DECEMBER) {
vMonthNames.add(dateFormat.format(epoch.getTime()));
index++;
epoch.add(Calendar.MONTH, 1);
}

// re initialize to 1st jan of the year
dt1 = stringToDate("01/01/" + annee, "dd/MM/yyyy");
epoch.setTime(dt1);

// fill the table of the current year
while (epoch.get(Calendar.YEAR) == annee) {
dayofweek = epoch.get(Calendar.DAY_OF_WEEK);
weekofmonth = epoch.get(Calendar.WEEK_OF_MONTH);
month = epoch.get(Calendar.MONTH);
if (epoch.get(Calendar.DAY_OF_MONTH) < 10)
semyear[month][weekofmonth][dayofweek] = "0"
+ Integer
.toString(epoch.get(Calendar.DAY_OF_MONTH));
else
semyear[month][weekofmonth][dayofweek] = Integer
.toString(epoch.get(Calendar.DAY_OF_MONTH));
epoch.add(Calendar.DAY_OF_YEAR, 1);
}

// Cycle for Lines of months
for (int monthboucle = 0; monthboucle < 3; monthboucle++) {
epoch = GregorianCalendar.getInstance(TimeZone.getDefault());
// *************************************************************************************
// Print month names
MonthTitle = ((String) vMonthNames.get(0 + monthboucle * 4));
for (int i = MonthTitle.length(); i < 22; i++)
MonthTitle += " ";// up to char pos 22
MonthTitle += ((String) vMonthNames.get(1 + monthboucle * 4));
for (int i = MonthTitle.length(); i < 44; i++)
MonthTitle += " ";// up to char pos 44
MonthTitle += ((String) vMonthNames.get(2 + monthboucle * 4));
for (int i = MonthTitle.length(); i < 66; i++)
MonthTitle += " ";// up to char pos 66
MonthTitle += ((String) vMonthNames.get(3 + monthboucle * 4));
System.out.println(MonthTitle);

// Show days name
for (int i = 0; i < 4; i++) {
for (int j = epoch.getFirstDayOfWeek() - 1; j < 7; j++)
System.out.print(((String) vDayNames.get(j)).substring(
0, 2)
+ " ");
if (epoch.getFirstDayOfWeek() > 1)
for (int j = 0; j < epoch.getFirstDayOfWeek() - 1; j++)
System.out.print(((String) vDayNames.get(j))
.substring(0, 2)
+ " ");
System.out.print(" ");
}
System.out.println("");

// print a line of months
for (weekofmonth = 0; weekofmonth < 6; weekofmonth++)// 6
// lines
// per
// months
{
for (month = 0; month < 4; month++) // 4 months per line
{
for (int day = epoch.getFirstDayOfWeek(); day < 8; day++) // 7
// days
// per
// week
{
System.out
.print(semyear[month + monthboucle * 4][weekofmonth][day]);
if ((annee == epoch.get(Calendar.YEAR))
&& // test to put a "<" after the current
// day
((month + monthboucle * 4) == epoch
.get(Calendar.MONTH))
&& (semyear[month+monthboucle*4][weekofmonth][day].trim().length()!=0)
&& (Integer
.parseInt(semyear[month
+ monthboucle * 4][weekofmonth][day]
.trim()) == epoch
.get(Calendar.DAY_OF_MONTH)))
System.out.print("<");
else
System.out.print(" ");
}
if (epoch.getFirstDayOfWeek() > 1)
for (int day = 1; day < epoch.getFirstDayOfWeek(); day++) {
System.out.print(semyear[month + monthboucle
* 4][weekofmonth][day]);
if ((annee == epoch.get(Calendar.YEAR))
&& // test to put a "<" after the
// current day
((month + monthboucle * 4) == epoch
.get(Calendar.MONTH))
&& (semyear[month+monthboucle*4][weekofmonth][day].trim().length()!=0)
&& (Integer
.parseInt(semyear[month
+ monthboucle * 4][weekofmonth][day]
.trim()) == epoch
.get(Calendar.DAY_OF_MONTH)))
System.out.print("<");
else
System.out.print(" ");
}
System.out.print(" ");// split to next month on the
// same line
}
System.out.println("");// New line after week printed for 4
// months

}
System.out.println(""); // new line after the "Months line"
// *************************************************************************************
}// endfor
} catch (Exception e) {
e.printStackTrace();
}

}

public static Date stringToDate(String sDate, String sFormat)
throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat(sFormat);
return sdf.parse(sDate);
}

}
  PS: Plus d'erreurs a la compil

signaler à un administrateur
Commentaire de dje_jay le 26/09/2007 17:15:41

"Au secours !" pour?
Ca a l'air de fonctionner...
C'est le décalage qui t'en*? =>C'est prévu pour tourner en terminal "normal" avec une fonte de type courrier, ou [fixed width] en ts cas...

Ajouter un commentaire

Discussions en rapport avec ce code source dans le forum

Méthode Protected [ par syndrael ] Voici mon code et j'aimerai pouvoir accéder à getTimeInMillis(), mais j'ai une erreur. Pouvez vous m'aider ?GregorianCalendar greday = new GregorianCa SimpleDateFormat et Locale [ par jmg02001 ] Bonjour, je sais utiliser SimpleDateFormat avec 1 seul paramettre mais pas avec 1 Locale en plus et ne voi pas à quoi sa sert,ni meme le DateFormatSym jtable+rafraichir [ par KERKENNAH ] bonjour &#224; tous je suis un etudiant et j'ai besoin d'aide &#224;proposde jtableon faite j'ai une application qui joue le role d'un serveur qui rec Problème de dates [ par scaryman ] bonjour a tous, voila le code que j'utilise : &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Calendar cal = new GregorianCalendar(2005, 8, 8); //mettre le cal n° de mois d'une de la date systeme ??? [ par alonsyl ] bonjour,je cherche a connaitre le n&#176; de mois d'une de la date systeme (et le n&#176; du jour dans le mois).&nbsp;j'arrive a avoir la date complet code avec erreur débutant JSP [ par Ephedra ] Bonjour,c'est pour  la recherche du sujet et de son affichage pour un forum.voici le code :     &lt;/tr&gt;     &lt;% EnsembleMessages sujets = new En calcul du numero de semaine [ par lkryss ] Bonjour, J'ai un leger probleme avec le calcul du numero de semaine. Aujourdhui nous sommes dans la 23ème semaine (selon les normes) hors, mon program mauvais format de date [ par nezdeboeuf62 ] bonjour a tous..j'ai un probleme pour manipuler des dates et surtout les formattées pour affichage.J'ai un object Calendar :        Calendar date=Cale Simpledateformat [ par deterred ] Bonjour,Je souhaite obtenir la date courante sous le format : Fri, 29 Dec 2006 23:57:10 +0100J'ai donc fait ceci : <b Problème dans les Date avec SimpleDateFormat [ par Luc1an0 ] Bonjour à tous, pour vous situer le contexte, j'ai une application principale qui créer des dossiers chaque jour avec la date de ce meme jour. Une foi


Nos sponsors

Sondage...

CalendriCode

Décembre 2008
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
293031    

Consulter la suite du CalendriCode

Téléchargements

Logiciels à télécharger sur le même thème :



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel BAÏSE, Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,343 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.