Visualizzazione dei risultati da 1 a 7 su 7
  1. #1
    Utente di HTML.it L'avatar di morphy79
    Registrato dal
    Jun 2004
    Messaggi
    1,568

    [java] data di un giorno della settimana !!!

    Ciao a tutti... sto facendo una conversione di una mia pagina asp...

    sono arrivato ad una funzione che dati anno, mese, numero settimana e giorno ti restiuisce la data corrispondente...

    codice:
    ' FUNZIONE CHE RESTITUISCE LA DATA DA MESE, ANNO, NUMERO SETTIMANA, GIORNO SETTIMANA
    Function dhNthWeekday(mese, anno, numeroSett, giornoSett )    ' Find the date of the specified day within the month. For
    	If (giornoSett < vbSunday or giornoSett > vbSaturday) Or (numeroSett < 1) Then
    		' Invalid parameter values
    		dhNthWeekday = ""
    		Exit Function
    	End If
    	' Get the first of the month.
    	dtmTemp = DateSerial(Year(mese & "/" & anno), Month(mese & "/" & anno), 1)
    	' Get to the first giornoSett in the month.
    	Do While WeekDay(dtmTemp) <> giornoSett
    		dtmTemp = dtmTemp + 1
    	Loop
    	' Now you've found the first giornoSett in the month.
    	' Just add 7 for each numeroSett after that.
    	dhNthWeekday = dtmTemp + ((numeroSett - 1) * 7)
    End Function
    qualcuno sa come fare questa operazione in java ??
    odio chi parla di politica..
    anzi vorrei fondare un partito contro tutto ciò

  2. #2
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    Calendar...

    una cosa del tipo

    codice:
    import java.util.Calendar;
    
    public class giochiamoConCalendar {
      
      private Calendar c;
      private String data;
      
      public String toString() {
        return data;    
      }
      
      public giochiamoConCalendar(int year, int month, int week_of_month, int day_of_week) {
        c = Calendar.getInstance();
        c.set(Calendar.YEAR, year);
        c.set(Calendar.MONTH, month);
        c.set(Calendar.WEEK_OF_MONTH, week_of_month);
        c.set(Calendar.DAY_OF_WEEK, day_of_week);
        data = c.getTime().toString();
      }
      
      public static void main (String[] args) {
        //i mesi e le settimane nel mese partono da 0 //
        //questo ti dovrebbe restituire capodanno//
        giochiamoConCalendar g = new giochiamoConCalendar(2006, 0, 0, 1);
        System.out.println(g);
      }
    }
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  3. #3
    Utente di HTML.it L'avatar di morphy79
    Registrato dal
    Jun 2004
    Messaggi
    1,568
    azzz... perfetto direi... ora provo...
    grazie, purtroppo con la classe Calendar ho sempre avuto "contrasti"...
    la odio, non so il perchè ma mi è ostica !!!
    grazie 1000
    odio chi parla di politica..
    anzi vorrei fondare un partito contro tutto ciò

  4. #4
    Utente di HTML.it L'avatar di morphy79
    Registrato dal
    Jun 2004
    Messaggi
    1,568
    ehmmm... ultimissima domanda... come faccio a convertire la data che mi risetituisce in formato "dd/MM/yyyy" ???
    odio chi parla di politica..
    anzi vorrei fondare un partito contro tutto ciò

  5. #5
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    codice:
    import java.util.Calendar;
    import java.text.SimpleDateFormat;
    
    public class giochiamoConCalendar {
    
      private Calendar c;
      private String data;
    
      public String toString() {
        return data;
      }
    
      public giochiamoConCalendar(int year, int month, int week_of_month, int day_of_week) {
        c = Calendar.getInstance();
        c.set(Calendar.YEAR, year);
        c.set(Calendar.MONTH, month);
        c.set(Calendar.WEEK_OF_MONTH, week_of_month);
        c.set(Calendar.DAY_OF_WEEK, day_of_week);
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        data = sdf.format(c.getTime());
      }
    
      public static void main (String[] args) {
        //i mesi e le settimane nel mese partono da 0 //
        //questo ti dovrebbe restituire capodanno//
        giochiamoConCalendar g = new giochiamoConCalendar(2006, 0, 0, 1);
        System.out.println(g);
      }
    }
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  6. #6
    Utente di HTML.it L'avatar di morphy79
    Registrato dal
    Jun 2004
    Messaggi
    1,568
    tutto funz !!!!
    grazie 1000
    odio chi parla di politica..
    anzi vorrei fondare un partito contro tutto ciò

  7. #7
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    Prego
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.