vba - 如何将忽略年份的儒略日期转换为儒略日
问题描述
如何在 Visual Basic 中将日/月转换为儒略日?其他语言的转换公式也值得赞赏。
例如,2 月 1 日的儒略日 = 032
https://landweb.modaps.eosdis.nasa.gov/browse/calendar.html
根据网络研究,大多数解决方案都将带有 yyyy-mm-dd 的日期转换为朱利安日期。
如上例,我需要获取值 032
解决方案
首先,您必须添加对 mscorlib 库的引用在 VB6 下,Project-References->勾选 mscorlib 复选框
在您拥有的对象中创建此函数方法或以其他方式创建子过程
Public Function JulianConverter() As String
'MsgBox Fix(5.2), vbExclamation, App.Title
'MsgBox Fix(5.6)
Dim y As String
Dim m As String
Dim d As String
Dim strDate As String
Dim dateArray() As String
strDate = Format(Now, "dd/MMM/yyyy")
dateArray = Split(strDate, "/")
d = dateArray(0)
m = dateArray(1)
y = dateArray(2)
'Debug
'MsgBox strDate
'Convert to Integer
y = Val(y)
m = Val(m)
d = Val(d)
If m <= 2 Then
y = y - 1
m = m + 12
End If
'Dim A As Double
' Dim B As Double
'Dim JD As Double
' A = CDbl(Fix(y / 100#))
'B = 2 - A + Fix(A / 4)
'JD = Fix(365.25 * (y + 4716)) + Fix(30.6001 * (m + 1)) + d + B - 1524.5
'JulianConverter = CStr(JD) 'Convert to string
Dim jc As mscorlib.JulianCalendar
Set jc = New mscorlib.JulianCalendar
' create a gregorian equivalent of the julian date: 1 Feb 2018
Dim gregoriaDateEquivalent As Date
gregoriaDateEquivalent = jc.ToDateTime(2018, m, d, 0, 0, 0, 0)
' = #2/14/2018
Dim dayOfYear As Long
Dim dayOfYearS As String
Dim digitLength As Integer
Dim Counter As Integer
dayOfYear = jc.GetDayOfYear(gregoriaDateEquivalent)
'Have to ensure 3 digits values
dayOfYearS = CStr(dayOfYear)
'Count number of Digits of string
digitLength = Len(dayOfYearS)
MsgBox "DigitLength" & digitLength, vbExclamation, App.Title
'If Digits length smaller than 3,add one 0 in front
If (digitLength < 3) Then
dayOfYearS = "0" & dayOfYearS
End If
JulianConverter = dayOfYearS
End Function
这将确保儒略日的值基于当前系统日期为 3 位数
推荐阅读
- python - 在给定时间范围内将 Stock Return/PopSTD 导出为 csv
- reactjs - 节点抛出“TypeError:无法读取 null 的属性 '1'”错误
- fastapi - 以编程方式解决 FastAPI 中的依赖关系,或可配置的依赖关系
- python - 解析部分并在两者之间获取行
- angular - Angular - 并非所有代码路径都返回值(参数)事件:HttpEvent
- sql-server - PAGEIOLATCH_SH 不在 SQL Server 中发布
- r - 使用 R 输出 chisq.test 的问题
- latex - 如何在 Latex 图中插入希腊字母而不弄乱格式
- javascript - React + Rsuite 下拉菜单:当下拉项目离开屏幕时防止页面向下滚动
- c# - 是否可以将代码中的字符串附加到 Base64 字符串并使用该字符串创建新图像?