Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如何将忽略年份的儒略日期转换为儒略日_Vba_Vb.net_Julian Date - Fatal编程技术网

Vba 如何将忽略年份的儒略日期转换为儒略日

Vba 如何将忽略年份的儒略日期转换为儒略日,vba,vb.net,julian-date,Vba,Vb.net,Julian Date,如何在visual basic中将日/月转换为朱利安日? 也欢迎使用其他语言进行转换的公式 例如 2月1日朱利安日=032 根据网上的研究,大多数解决方案都是将yyyy-mm-dd日期转换为朱利安日期 如上面的例子所示,我需要得到值032。您需要年份,这样您就可以知道哪一天是日期。Net公开了实现目标所需的所有方法。它也是COM可见的,因此在将项目引用添加到“mscorlib.dll”后,可以在VBA项目中引用它 在VB.Net中,代码为: Dim jc As New System.Globa

如何在visual basic中将日/月转换为朱利安日? 也欢迎使用其他语言进行转换的公式

例如 2月1日朱利安日=032

根据网上的研究,大多数解决方案都是将yyyy-mm-dd日期转换为朱利安日期


如上面的例子所示,我需要得到值032。您需要年份,这样您就可以知道哪一天是日期。

Net公开了实现目标所需的所有方法。它也是COM可见的,因此在将项目引用添加到“mscorlib.dll”后,可以在VBA项目中引用它

在VB.Net中,代码为:

Dim jc As New System.Globalization.JulianCalendar
' create a gregorian equivalent of the julian date: 1 Feb 2018
Dim gregoriaDateEquivalent As DateTime = jc.ToDateTime(2018, 2, 1, 0, 0, 0, 0)
' = #2/14/2018 12:00:00 AM#
Dim dayOfYear As Int32 = jc.GetDayOfYear(gregoriaDateEquivalent)
' = 32
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, 2, 1, 0, 0, 0, 0)
' = #2/14/2018
Dim dayOfYear As Long
dayOfYear = jc.GetDayOfYear(gregoriaDateEquivalent)
' = 32
在VBA中,代码为:

Dim jc As New System.Globalization.JulianCalendar
' create a gregorian equivalent of the julian date: 1 Feb 2018
Dim gregoriaDateEquivalent As DateTime = jc.ToDateTime(2018, 2, 1, 0, 0, 0, 0)
' = #2/14/2018 12:00:00 AM#
Dim dayOfYear As Int32 = jc.GetDayOfYear(gregoriaDateEquivalent)
' = 32
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, 2, 1, 0, 0, 0, 0)
' = #2/14/2018
Dim dayOfYear As Long
dayOfYear = jc.GetDayOfYear(gregoriaDateEquivalent)
' = 32

首先,您必须添加对mscorlib库的引用 在VB6下,项目引用->勾选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
公共函数JulianConverter()作为字符串
'MsgBox修复程序(5.2),VBEquiremon,App.Title
'MsgBox修复程序(5.6)
朦胧如弦
把m调成线
将d变暗为字符串
作为字符串的Dim strDate
Dim dateArray()作为字符串
标准日期=格式(现在为“dd/MMM/yyyy”)
dateArray=Split(标准日期,“/”)
d=日期数组(0)
m=日期数组(1)
y=日期数组(2)
"调试",
'MsgBox strDate
'转换为整数
y=Val(y)
m=Val(m)
d=Val(d)

如果我没有年份,你将如何处理闰年?你所说的其他语言是指英语或其他编程语言以外的语言吗?如果可以输入年份,
DateTime.DayOfYear
可能会起作用。一年中月份的天数与公历相同,但闰年略有不同,因为它没有闰年的100年例外。所以,正如@Mary所说,你仍然需要包括年份。我的意思是,给定一年、一个月、一天,儒略日是基于我给出的链接,只有3位数的值,我该怎么做呢?正常的在线儒略日转换器是基于转换后超过3位数的日期。“其他语言”是指任何其他编程语言,我只需要研究转换的编程逻辑。任何编程语言都可以,但最好是vb6。我正在研究的环境澄清您的问题,从1900年3月1日起,结果是60还是61?@ThomasKoh,如果“有效”考虑把它标记为答案。