我怎样才能获得一周的周数? VB.NET [英] How can I get week number of month? VB.NET

查看:202
本文介绍了我怎样才能获得一周的周数? VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,请告诉我如何获得一周的周数?我有这个代码,但现在是一个月的第三周,代码显示我第二。你能帮我吗?谢谢

Hello, please can you tell me how can I get week number of month? I have this code but now is third week of month and code show me second. Can you help me please? Thank you

Public Shared Function GetWeekNumber(ByVal datum As Date) As Integer
 
       Dim weeknumber = Math.Floor(datum.Day / 7 + 1)
 
       SendKeys.Send(weeknumber)
       Return weeknumber
 
   End Function

推荐答案

您好

尝试一下.Button2事件处理程序仅用于通过每次点击一天增加日期来进行测试。

Give this a try.The Button2 event handler is just for testing by increasing the Date by one day per click.

BTW:SendKeys需要一个字符串。如果将Option Strict On置于代码顶部,则有助于消除这些类型的错误。

BTW: the SendKeys needs a string. If you put the Option Strict On at top of your code, it would help eliminate those kinds of errors.

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    ' testing with increasing date
    Static d As Integer = 0
    Label1.Text = GetWeekNumber(Now.AddDays(d)).ToString
    d += 1
  End Sub
  Public Shared Function GetWeekNumber(ByVal datum As Date) As Integer
    Return (datum.Day - 1) \ 7 + 1
  End Function


这篇关于我怎样才能获得一周的周数? VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆