Visualizzazione dei risultati da 1 a 9 su 9
  1. #1

    Convertire la data in formato Giuliano

    Ragazzi sapete per caso se esiste ua funzione già bella e pronta per ricavare la data in formato Giuliano o devo crearmela io?

    Response.Write("Tonyhhkx Programmer32");

  2. #2
    Moderatore di ASP.net L'avatar di djciko
    Registrato dal
    Nov 2002
    Messaggi
    6,887
    Da un vecchio thread, il buon Pietro09 postò l'algoritmo traducendolo da Wikipedia [http://it.wikipedia.org/wiki/Data_giuliana]:

    codice:
        Public Function DataNormaleDataGiuliana(ByVal dataAttuale As DateTime) As Double
            Dim anno As Integer = dataAttuale.Year
            Dim mese As Integer = dataAttuale.Month
            Dim giorno As Integer = dataAttuale.Day
            Dim ore As Integer = dataAttuale.Hour
            Dim minuti As Integer = dataAttuale.Minute
            Dim secondi As Integer = dataAttuale.Second
            Dim millisecondi As Integer = dataAttuale.Millisecond
    
            If mese = 1 OrElse mese = 2 Then
                anno -= 1
                mese += 12
            End If
    
            Dim a, b, c, d As Integer
    
            If dataAttuale < New DateTime(1582, 10, 15) Then
                a = 0
                b = 0
            Else
                a = CInt(Math.Floor(anno / 100))
                b = 2 - a + CInt(Math.Floor(a / 4))
            End If
    
            c = CInt(Math.Floor(365.25 * anno))
            d = CInt(Math.Floor(30.6001 * (mese + 1)))
    
            Dim dataGiuliana As Double = b + c + d + giorno + 1720994.5 '- reset
    
            Dim offsetGiornata As Double = ore / 24
            offsetGiornata = (60 * ore + minuti) / 1440
            offsetGiornata = (3600 * ore + 60 * minuti + secondi) / 86400
    
            Return dataGiuliana + offsetGiornata
    
        End Function
    
        Public Function DataGiulianaDataNormale(ByVal dataGiuliana As Double) As DateTime
            Dim jd As Double = dataGiuliana
            Dim i As Integer = CInt(Math.Floor(jd + 0.5))
            Dim f As Double = jd + 0.5 - i
            Dim a, b, c, d, e, h As Integer
    
            If i <= 2299160 Then
                b = i
            Else
                a = CInt(Math.Floor((i - 1867216.25) / 36524.25))
                b = i + 1 + a - CInt(Math.Floor(a / 4))
            End If
            c = b + 1524
            d = CInt(Math.Floor((c - 122.1) / 365.25))
            e = CInt(Math.Floor(365.25 * d))
            h = CInt(Math.Floor((c - e) / 30.6001))
    
            Dim giorno As Double = (c - e + f - CInt(Math.Floor(30.6001 * h)))
            Dim mese, anno As Double
            If h < 14 Then
                mese = h - 1
            Else
                mese = h - 13
            End If
    
            If mese < 3 Then
                anno = d - 4715
            Else
                anno = d - 4716
            End If
    
            Dim offsetGiornata, ore, minuti, secondi As Double
    
            offsetGiornata = ((dataGiuliana - CInt(Math.Floor(dataGiuliana))) * 86400)
            ore = Math.Floor((offsetGiornata / 3600))
            minuti = Math.Floor((offsetGiornata - 3600 * ore) / 60)
            secondi = offsetGiornata - 3600 * ore + 60 * minuti
    
            Dim o, m, s As Integer
            o = CInt((ore + 12) Mod 24)
            m = CInt(minuti Mod 60)
            s = CInt(secondi Mod 60)
    
            If s = 60 Then
                s = 0
                m += 1
            End If
    
            If m = 60 Then
                m = 0
                o += 1
            End If
    
            Dim dataAttuale As DateTime = New DateTime(CInt(Math.Floor(anno)), CInt(Math.Floor(mese)), CInt(Math.Floor(giorno)), o, m, s)
    
            Return dataAttuale
    
        End Function

  3. #3
    Originariamente inviato da djciko
    Da un vecchio thread, il buon Pietro09 postò l'algoritmo traducendolo da Wikipedia [http://it.wikipedia.org/wiki/Data_giuliana]:

    codice:
        Public Function DataNormaleDataGiuliana(ByVal dataAttuale As DateTime) As Double
            Dim anno As Integer = dataAttuale.Year
            Dim mese As Integer = dataAttuale.Month
            Dim giorno As Integer = dataAttuale.Day
            Dim ore As Integer = dataAttuale.Hour
            Dim minuti As Integer = dataAttuale.Minute
            Dim secondi As Integer = dataAttuale.Second
            Dim millisecondi As Integer = dataAttuale.Millisecond
    
            If mese = 1 OrElse mese = 2 Then
                anno -= 1
                mese += 12
            End If
    
            Dim a, b, c, d As Integer
    
            If dataAttuale < New DateTime(1582, 10, 15) Then
                a = 0
                b = 0
            Else
                a = CInt(Math.Floor(anno / 100))
                b = 2 - a + CInt(Math.Floor(a / 4))
            End If
    
            c = CInt(Math.Floor(365.25 * anno))
            d = CInt(Math.Floor(30.6001 * (mese + 1)))
    
            Dim dataGiuliana As Double = b + c + d + giorno + 1720994.5 '- reset
    
            Dim offsetGiornata As Double = ore / 24
            offsetGiornata = (60 * ore + minuti) / 1440
            offsetGiornata = (3600 * ore + 60 * minuti + secondi) / 86400
    
            Return dataGiuliana + offsetGiornata
    
        End Function
    
        Public Function DataGiulianaDataNormale(ByVal dataGiuliana As Double) As DateTime
            Dim jd As Double = dataGiuliana
            Dim i As Integer = CInt(Math.Floor(jd + 0.5))
            Dim f As Double = jd + 0.5 - i
            Dim a, b, c, d, e, h As Integer
    
            If i <= 2299160 Then
                b = i
            Else
                a = CInt(Math.Floor((i - 1867216.25) / 36524.25))
                b = i + 1 + a - CInt(Math.Floor(a / 4))
            End If
            c = b + 1524
            d = CInt(Math.Floor((c - 122.1) / 365.25))
            e = CInt(Math.Floor(365.25 * d))
            h = CInt(Math.Floor((c - e) / 30.6001))
    
            Dim giorno As Double = (c - e + f - CInt(Math.Floor(30.6001 * h)))
            Dim mese, anno As Double
            If h < 14 Then
                mese = h - 1
            Else
                mese = h - 13
            End If
    
            If mese < 3 Then
                anno = d - 4715
            Else
                anno = d - 4716
            End If
    
            Dim offsetGiornata, ore, minuti, secondi As Double
    
            offsetGiornata = ((dataGiuliana - CInt(Math.Floor(dataGiuliana))) * 86400)
            ore = Math.Floor((offsetGiornata / 3600))
            minuti = Math.Floor((offsetGiornata - 3600 * ore) / 60)
            secondi = offsetGiornata - 3600 * ore + 60 * minuti
    
            Dim o, m, s As Integer
            o = CInt((ore + 12) Mod 24)
            m = CInt(minuti Mod 60)
            s = CInt(secondi Mod 60)
    
            If s = 60 Then
                s = 0
                m += 1
            End If
    
            If m = 60 Then
                m = 0
                o += 1
            End If
    
            Dim dataAttuale As DateTime = New DateTime(CInt(Math.Floor(anno)), CInt(Math.Floor(mese)), CInt(Math.Floor(giorno)), o, m, s)
    
            Return dataAttuale
    
        End Function
    ammazza!

    Niente in c#?
    Response.Write("Tonyhhkx Programmer32");

  4. #4
    Moderatore di ASP.net L'avatar di djciko
    Registrato dal
    Nov 2002
    Messaggi
    6,887
    codice:
     
    public double DataNormaleDataGiuliana(DateTime dataAttuale)
    {
    	int anno = dataAttuale.Year;
    	int mese = dataAttuale.Month;
    	int giorno = dataAttuale.Day;
    	int ore = dataAttuale.Hour;
    	int minuti = dataAttuale.Minute;
    	int secondi = dataAttuale.Second;
    	int millisecondi = dataAttuale.Millisecond;
    
    	if (mese == 1 || mese == 2) {
    		anno -= 1;
    		mese += 12;
    	}
    
    	int a = 0;
    	int b = 0;
    	int c = 0;
    	int d = 0;
    
    	if (dataAttuale < new DateTime(1582, 10, 15)) {
    		a = 0;
    		b = 0;
    	} else {
    		a = Convert.ToInt32(Math.Floor(anno / 100));
    		b = 2 - a + Convert.ToInt32(Math.Floor(a / 4));
    	}
    
    	c = Convert.ToInt32(Math.Floor(365.25 * anno));
    	d = Convert.ToInt32(Math.Floor(30.6001 * (mese + 1)));
    
    	double dataGiuliana = b + c + d + giorno + 1720994.5;
    	//- reset
    
    	double offsetGiornata = ore / 24;
    	offsetGiornata = (60 * ore + minuti) / 1440;
    	offsetGiornata = (3600 * ore + 60 * minuti + secondi) / 86400;
    
    	return dataGiuliana + offsetGiornata;
    
    }
    guarda che le funzioni che ho postato in VB erano due...

  5. #5
    Originariamente inviato da djciko
    codice:
     
    public double DataNormaleDataGiuliana(DateTime dataAttuale)
    {
    	int anno = dataAttuale.Year;
    	int mese = dataAttuale.Month;
    	int giorno = dataAttuale.Day;
    	int ore = dataAttuale.Hour;
    	int minuti = dataAttuale.Minute;
    	int secondi = dataAttuale.Second;
    	int millisecondi = dataAttuale.Millisecond;
    
    	if (mese == 1 || mese == 2) {
    		anno -= 1;
    		mese += 12;
    	}
    
    	int a = 0;
    	int b = 0;
    	int c = 0;
    	int d = 0;
    
    	if (dataAttuale < new DateTime(1582, 10, 15)) {
    		a = 0;
    		b = 0;
    	} else {
    		a = Convert.ToInt32(Math.Floor(anno / 100));
    		b = 2 - a + Convert.ToInt32(Math.Floor(a / 4));
    	}
    
    	c = Convert.ToInt32(Math.Floor(365.25 * anno));
    	d = Convert.ToInt32(Math.Floor(30.6001 * (mese + 1)));
    
    	double dataGiuliana = b + c + d + giorno + 1720994.5;
    	//- reset
    
    	double offsetGiornata = ore / 24;
    	offsetGiornata = (60 * ore + minuti) / 1440;
    	offsetGiornata = (3600 * ore + 60 * minuti + secondi) / 86400;
    
    	return dataGiuliana + offsetGiornata;
    
    }
    guarda che le funzioni che ho postato in VB erano due...
    scusa ma non me la cavo molto nel convertire prima o poi ci dovrò provare

    Comunque, ho provato il tuo codice, e mi da errore alle segienti righe:

    codice:
                a = Convert.ToInt32(Math.Floor(anno / 100));
                b = 2 - a + Convert.ToInt32(Math.Floor(a / 4));
    Errore 2 Chiamata ambigua tra i seguenti metodi o proprietà: 'System.Math.Floor(double)' e 'System.Math.Floor(decimal)' C:\Users\antonio\Desktop\MHelp\Sito\amministrazion e\pannelloAdmin.aspx.cs 39 33 C:\...\Sito\
    Response.Write("Tonyhhkx Programmer32");

  6. #6
    Moderatore di ASP.net L'avatar di djciko
    Registrato dal
    Nov 2002
    Messaggi
    6,887
    codice:
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(DataNormaleDataGiuliana(DateTime.Now));
        }
    
    
        public double DataNormaleDataGiuliana(DateTime dataAttuale)
        {
            int anno = dataAttuale.Year;
            int mese = dataAttuale.Month;
            int giorno = dataAttuale.Day;
            int ore = dataAttuale.Hour;
            int minuti = dataAttuale.Minute;
            int secondi = dataAttuale.Second;
            int millisecondi = dataAttuale.Millisecond;
    
            if (mese == 1 || mese == 2)
            {
                anno -= 1;
                mese += 12;
            }
    
            int a = 0;
            int b = 0;
            int c = 0;
            int d = 0;
    
            if (dataAttuale < new DateTime(1582, 10, 15))
            {
                a = 0;
                b = 0;
            }
            else
            {
                a = Convert.ToInt32(Math.Floor(Convert.ToDouble(anno / 100)));
                b = 2 - a + Convert.ToInt32(Math.Floor(Convert.ToDouble(a / 4)));
            }
    
            c = Convert.ToInt32(Math.Floor(365.25 * anno));
            d = Convert.ToInt32(Math.Floor(30.6001 * (mese + 1)));
    
            double dataGiuliana = b + c + d + giorno + 1720994.5;
            //- reset
    
            double offsetGiornata = ore / 24;
            offsetGiornata = (60 * ore + minuti) / 1440;
            offsetGiornata = (3600 * ore + 60 * minuti + secondi) / 86400;
    
            return dataGiuliana + offsetGiornata;
    
        }

  7. #7
    funzionaaaaaaaaaaa!!!!!!

    Grazie infinite djciko
    Response.Write("Tonyhhkx Programmer32");

  8. #8
    Moderatore di ASP.net L'avatar di djciko
    Registrato dal
    Nov 2002
    Messaggi
    6,887
    prego, ma controlla con un tool qualsiasi se le date convertite sono esatte

  9. #9
    va bene grazie ancora!
    Response.Write("Tonyhhkx Programmer32");

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 © 2025 vBulletin Solutions, Inc. All rights reserved.