简体   繁体   English

VB.net如何计算每月的15号和30号?

[英]VB.net How to Calculate the 15th and 30th of the month?

For example, the 15th of January is from Jan 1 to 15, and the 30th of January is Jan 1 to Jan 30. Since not all months are composed of 30 days, therefore the 15th of February will be from Jan 31 to February 14. So what could be the formula in getting the 15th and 30th of the PRESENT month? 例如,1月15日是1月1日至15日,1月30日是1月1日至1月30日。由于并非所有月份都由30天组成,因此2月15日将是1月31日至2月14日。那么获得当前月15号和30号的公式可能是什么? Thanks in advance. 提前致谢。

If I understand your question correctly, you want the number for which day of the year it is? 如果我正确理解了您的问题,您想要该数字是一年中的哪一天? If so you can do this 如果是这样,您可以这样做

Sub Main()
    Dim FIFTEENTH As DateTime = New DateTime(Now.Year, Now.Month, 15)
    Dim THIRTIETH As DateTime
    Dim hasThirty As Boolean = (DateTime.DaysInMonth(Now.Year, Now.Month) >= 30)

    Console.WriteLine("The fifteenth: ")
    Console.WriteLine($"Day of the Year: {FIFTEENTH.DayOfYear}")
    Console.WriteLine($"Day of the Week: {FIFTEENTH.DayOfWeek.ToString("D")} / {FIFTEENTH.DayOfWeek.ToString("g")}")

    If (hasThirty) Then
        Console.WriteLine("The Thirtieth: ")

        Console.WriteLine($"Day of the Year: {THIRTIETH.DayOfYear}")
        Console.WriteLine($"Day of the Week: {THIRTIETH.DayOfWeek.ToString("D")} / {THIRTIETH.DayOfWeek.ToString("g")}")
    End If

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM