codice:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="data_giuliana.aspx.vb" Inherits="CorsoApogeo_date_data_giuliana" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.data {width:50px; text-align:center}
.data_giuliana {width:150px; text-align:center}
.pulsante {border:none; background-color:Transparent;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<th>Anno</th>
<th>Mese</th>
<th>Giorno</th>
<th>Ora</th>
<th>Minuti</th>
<th>Secondi</th>
<th></th>
<th>Data giuliana</th>
</tr>
<tr>
<td><asp:TextBox ID="anno" runat="server" CssClass="data" Text="2009" /></td>
<td><asp:TextBox ID="mese" runat="server" CssClass="data" Text="4" /></td>
<td><asp:TextBox ID="giorno" runat="server" CssClass="data" Text="9" /></td>
<td><asp:TextBox ID="ora" runat="server" CssClass="data" Text="19" /></td>
<td><asp:TextBox ID="minuti" runat="server" CssClass="data" Text="47" /></td>
<td><asp:TextBox ID="secondi" runat="server" CssClass="data" Text="50" /></td>
<td>
<asp:Button ID="Button1" runat="server" Text="==>" CssClass="pulsante" />
<asp:Button ID="Button2" runat="server" Text="<==" CssClass="pulsante" />
</td>
<td><asp:TextBox ID="data_giuliana" runat="server" CssClass="data_giuliana" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
codice:
Option Strict On
Imports l = libreria.ModuloWeb
Partial Class CorsoApogeo_date_data_giuliana
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.data_giuliana.Text = ""
Dim dataAttuale As New DateTime(CInt(Me.anno.Text), CInt(Me.mese.Text), CInt(Me.giorno.Text), CInt(Me.ora.Text), CInt(Me.minuti.Text), CInt(Me.secondi.Text))
Me.data_giuliana.Text = DataNormaleDataGiuliana(dataAttuale).ToString
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.anno.Text = ""
Me.mese.Text = ""
Me.giorno.Text = ""
Me.ora.Text = ""
Me.minuti.Text = ""
Me.secondi.Text = ""
Dim dataAttuale As DateTime = DataGiulianaDataNormale(CDbl(Me.data_giuliana.Text))
Me.anno.Text = dataAttuale.Year.ToString
Me.mese.Text = dataAttuale.Month.ToString
Me.giorno.Text = dataAttuale.Day.ToString
Me.ora.Text = dataAttuale.Hour.ToString
Me.minuti.Text = dataAttuale.Minute.ToString
Me.secondi.Text = dataAttuale.Second.ToString
End Sub
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
End Class