Extract Hours, Minutes & Seconds from TIME

Dead Soul

New member
Joined
Jan 15, 2009
Messages
2
Programming Experience
Beginner
Hi every one i need help in extracting parts of time like Hours , Minutes , Seconds and Milliseconds

here is what i tried but it jus give a zero "0" result i want it to display the hour. But actually i want it to extract HOURS, MINUTES , SECONDS individually so as to manipulate the values

Public Class Form1

Private Sub btngenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngenerate.Click
Dim h, m, s As Integer
Dim str As String
Dim dt As Date
str = dt.TimeOfDay.Hours

txtname.Text = str
End Sub



End Class
 
Dim S '// Seconds
Dim H '// Hours
Dim M '// Minutes
Dim Spl() As String = Split(TimeOfDay, ":")
S = Spl(2) '// Returns Seconds
H = Spl(0) '// Returns Hours
M = Spl(1) '// Returns Minutes

Works fine for me ;)
 
1. Please use CODE tags in your posts - it makes quoted code much easier to read :)

2. Use Option Strict On in your code - it will eliminate conversion problems.

3. Your code is actually working fine - it's just not giving you the answer you were expecting. Change this code :-

VB.NET:
        Dim dt As Date
        str = dt.TimeOfDay.Hours

        txtname.Text = str

to this

VB.NET:
        Dim dt As Date
        MessageBox.Show(dt.ToString)
        str = dt.TimeOfDay.Hours

        txtname.Text = str

and see if this gives you some direction :)
 
Back
Top