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 / Exemple :
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];
/**
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...
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.