Simple Date Time(s)

Paladine -1 Tallied Votes 152 Views Share

An example of using the ToString() DateTime Strings to produce common date & time output formats in Visual Basic.Net

'   Declarations
        Dim dtNow As DateTime = DateTime.Now
        Dim intHour As Integer = Now.Hour
        Dim intMin As Integer = Now.Minute
        Dim intSec As Integer = Now.Second

        '  Logic
        If intHour < 12 Then
            lblGreeting.Text = "Good Morning"
        ElseIf intHour > 12 & intHour < 18 Then
            lblGreeting.Text = "Good Afternoon!"
        Else
            lblGreeting.Text = "Good Evening!"
        End If

        '   <summary>
        '   Sample examples of DateTime Strings you can use
        '   
        '   DateTime String                 Sample Result
        '       "D"                     Thursday, February 01, 2001
        '       "d"                     2/01/2001
        '       "f"                     Thursday, February 01, 2001 4:32 PM
        '       "F"                     Thursday, February 01, 2001 4:32:30 PM
        '       "g"                     2/01/2001 4:32 PM
        '       "G"                     2/01/2001 4:32:30 PM
        '       "m"                     February 01
        '       "t"                     4:32 PM
        '       "T"                     4:32:30 PM
        '       "dddd, MMMM dd yyyy"    Thursday, February 01 2001
        '   
        '   </summary>

        lblDate.Text = "The Current Date and Time is: " + Now.ToString("F")
a.j. 0 Newbie Poster

THANX MAN....this is a good one. after i saw smone code a clock in VB....I always wanted to know how that works b'cos i noticed that everytime it run, it was synchronized with the time on the pc.
thanx for opening ma mind, thanx


Aj..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.