2017-08-18 97 views
0

我收到朱利安日期和時間從JDE表:朱利安日期和時間到正規的日期和時間

SLUPMJ(Date) | SLTDAY(Time) 
--------------------------- 
116173  | 94959 

我需要將它們轉換成普通的日期和時間值融入我的應用程序。

雖然我能夠演唱會使用日期部分自定義代碼:

DCY = Left(Date1, 3) 

If Left(DCY, 1) = "0" Then 
    DYear = "19" & Right(DCY, 2) 
Else 
    DYear = "20" & Right(DCY, 2) 
End If 

Dinterval = CInt(Right(Date1, 3)) 

TDate = DateAdd("d", Dinterval - 1, "01/01/" & DYear) 
J2D2 = Day(TDate) & "/" & Month(TDate) & "/" & Year(TDate) 

如何轉換在vb.net部分時間?

+0

檢查[這裏](https://stackoverflow.com/questions/6883324/date-time -format-convert-in-vb-net?rq = 1)可能有幫助 – JSON

+0

您應該向我們展示給定輸入的輸出結果。如果你可以提供一個描述輸入格式的參考文件,那也是很好的。 – Enigmativity

+0

如果結果是星期三,B.C. 4395 Jan 25 \t 10:47:24.6? http://aa.usno.navy.mil/jdconverter?ID=AA&jd=116173.94959 – Slai

回答

1

下面是一些代碼來轉換Julian日期時間的時間部分。有可能是一個更簡單的方法,但編碼應該不難!™ :)

''' <summary> 
''' Converts the time portion of a Julian datetime 
''' </summary> 
''' <param name="dJDateTime">The Julian datetime. For example: 2457984.021181</param> 
''' <returns>The time, formatted as follows: d:hh:mm:ss.mmm</returns> 
Function ConvertJulianTime(ByVal dJDateTime As Decimal) As String 
    ' Julian time is calculated as a fraction of a 24-hour period, starting from noon. 
    ' So a value >= .5 is a morning hour on the next day 

    ' Get the fractional part of the Julian datetime, which is the time 
    Dim dJTime As Decimal = GetFractionalPart(dJDateTime) 
    ' Get time in seconds 
    Dim dJTimeInSec As Decimal = 86400 * dJTime + 43200 ' 43200 is half a day in seconds 
    ' Calculate the hours 
    Dim dJTimeInHours As Decimal = dJTimeInSec/3600 
    ' If the value is >= 24, it's a morning hour so increment the day value 
    Dim intDay As Integer = 0 
    If dJTimeInHours >= 24 Then 
     dJTimeInHours = dJTimeInHours - 24 
     intDay = 1 
    End If 
    ' Calculate the minutes 
    Dim dJTimeInHoursMin As Decimal = GetFractionalPart(dJTimeInHours) * 60 
    ' Calculate the seconds 
    Dim dJTimeInHoursSec As Decimal = GetFractionalPart(dJTimeInHoursMin) * 60 
    ' Calculate the milliseconds 
    Dim dJTimeInHoursMSec As Decimal = GetFractionalPart(dJTimeInHoursSec) * 1000 
    ' Build the result and display it 
    Dim tsSpan As New TimeSpan(intDay, CInt(Math.Truncate(dJTimeInHours)), 
           CInt(Math.Truncate(dJTimeInHoursMin)), 
           CInt(Math.Truncate(dJTimeInHoursSec)), 
           CInt(Math.Truncate(dJTimeInHoursMSec))) 
    Return tsSpan.ToString("d\:hh\:mm\:ss\.fff") 
End Function 
''' <summary> 
''' Given a decimal, gets the fractional part only. For example, for 1234.5678, returns 0.5678 
''' </summary> 
''' <param name="dNumber">The decimal.</param> 
''' <returns>The fractional part of the decimal.</returns> 
Function GetFractionalPart(ByVal dNumber As Decimal) As Decimal 
    Dim dInt As Decimal = Math.Truncate(dNumber) 
    Return (dNumber - dInt) 
End Function 

末級

+0

爲什麼我的代碼不被接受? – Squidx3