Display hours of day in 24 hour in listview

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2008
Posts: 115
Reputation: ninjaimp is an unknown quantity at this point 
Solved Threads: 6
ninjaimp ninjaimp is offline Offline
Junior Poster

Display hours of day in 24 hour in listview

 
0
  #1
Jun 23rd, 2008
Hi

I am trying to populate a listview with all the hours of the day in 30 minute intervals.

I can doing very basically from 0 to 24 with the following code:

  1.  
  2. Private Sub CreateTimeStep()
  3.  
  4. For i = 0 To 25 Step 0.5
  5.  
  6. lstDays.Items.Add(i)
  7.  
  8. Next
  9. End Sub


but what i would like to do is have it display in 24 hour format e.g. 00:00, 00:30 ...etc

I have tried using the date.time variable but it just doesnt work.
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: Display hours of day in 24 hour in listview

 
0
  #2
Jun 23rd, 2008
Try this:
  1. Dim d As Date = "00:00:00"
  2. For x As Integer = 0 To 47
  3. ListBox1.Items.Add(d.TimeOfDay.ToString)
  4. d = d.AddMinutes(30)
  5. Next
Last edited by waynespangler; Jun 23rd, 2008 at 1:37 pm.
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 115
Reputation: ninjaimp is an unknown quantity at this point 
Solved Threads: 6
ninjaimp ninjaimp is offline Offline
Junior Poster

Re: Display hours of day in 24 hour in listview

 
0
  #3
Jun 23rd, 2008
this looks like just the thing - many thanks - will update when tested
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 115
Reputation: ninjaimp is an unknown quantity at this point 
Solved Threads: 6
ninjaimp ninjaimp is offline Offline
Junior Poster

Re: Display hours of day in 24 hour in listview

 
0
  #4
Jun 23rd, 2008
hi

your code worked fine but i just needed to get rid of the last zeros so used the following

Dim d As DateTime = FormatDateTime("00:00")
For x As Integer = 0 To 47
lstDays.Items.Add(FormatDateTime(d.TimeOfDay.ToString, DateFormat.ShortTime))
d = d.AddMinutes(30)
Next
End Sub
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC