0

I made a timer which refreshes every 1000 milliseconds and I put the code as:

Private Sub RealTimeTMR_Tick(sender As Object, e As EventArgs) Handles RealTimeTMR.Tick
    TimeLBL.Text = TimeOfDay.ToLocalTime.ToString
End Sub

One would suspect this to be flawless and simple but when I start the program I get the value of the label as: 01/01/0001 18:59:36

If it make any difference to formats or anything I live in Ireland.

Kraxed
  • 352
  • 2
  • 11
  • 26

2 Answers2

3

It's because TimeOfDay only does the time component and has its Date component set to all 1's.

You could use something like DateTime.Now to get this information - it should return the current local date and time of the machine it's executed on.

nkvu
  • 5,551
  • 2
  • 16
  • 12
3

If you only want the time, use:

TimeLBL.Text = DateTime.Now.TimeOfDay.ToString("g")

See Standard TimeSpan Format Strings and Custom TimeSpan Format Strings for more information about formatting.

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351