Julian Date
Posted: 07.06.2003, 22:25
how i convert julian date to "normal dat" and the oposite?
Real-time 3D visualization of space
https://celestiaproject.space/forum/
https://celestiaproject.space/forum/viewtopic.php?f=2&t=2530
Code: Select all
Function JulianToDate(ByVal plJulian As Long) As Date
Dim sJulian As String
Dim bCentury As Byte
Dim iYear As Integer
Dim iDay As Integer
' Pad with leading zeros
sJulian = String(6 - Len(CStr(plJulian)), "0") + CStr(plJulian)
' Breakdown...
bCentury = CByte(Left(sJulian, 1))
iYear = (1900 + (bCentury * 100) + CByte(Mid(sJulian, 2, 2)))
iDay = CInt(Mid(sJulian, 4, 3))
' Return the gregorian date
JulianToDate = DateAdd("d", iDay - 1, DateSerial(iYear, 1, 1))
End Function
Code: Select all
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 1545
ClientLeft = 1620
ClientTop = 1755
ClientWidth = 2610
LinkTopic = "Form1"
ScaleHeight = 1545
ScaleWidth = 2610
Begin VB.CommandButton Command1
Caption = "Get Date"
Default = -1 'True
Height = 375
Left = 120
TabIndex = 2
Top = 1080
Width = 2295
End
Begin VB.TextBox Text1
Height = 375
Left = 120
TabIndex = 1
Text = "<Enter Julian Number Here>"
Top = 600
Width = 2235
End
Begin VB.Label Label1
Height = 375
Left = 120
TabIndex = 0
Top = 120
Width = 2295
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Function JulianToDate(ByVal plJulian As Long) As Date
Dim sJulian As String
Dim bCentury As Byte
Dim iYear As Integer
Dim iDay As Integer
' Pad with leading zeros
sJulian = String(6 - Len(CStr(plJulian)), "0") + CStr(plJulian)
' Breakdown...
bCentury = CByte(Left(sJulian, 1))
iYear = (1900 + (bCentury * 100) + CByte(Mid(sJulian, 2, 2)))
iDay = CInt(Mid(sJulian, 4, 3))
' Return the gregorian date
JulianToDate = DateAdd("d", iDay - 1, DateSerial(iYear, 1, 1))
End Function
Private Sub Command1_Click()
If IsNumeric(Text1) And Len(Text1) <= 6 Then
Label1 = JulianToDate(Text1)
End If
Text1.SetFocus
Text1_GotFocus
End Sub
Private Sub Text1_GotFocus()
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
End Sub
Private Sub Text1_Validate(cancel As Boolean)
If Not (IsNumeric(Text1) And Len(Text1) <= 6) Then
cancel = True
Text1.SetFocus
End If
End Sub