Results 1 to 3 of 3

Thread: [RESOLVED] Digital clock

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Resolved [RESOLVED] Digital clock

    hi guys! what is the best way to put a digital clock in a windows application? because currently the code below is my solution but i dont know if that is the best way or the right way to do that...any suggestions will be greatly appreciated..thanks in advance!

    Code:
            private void TimerClock_Tick(object sender, EventArgs e)
            {
                lblDateTime.Text = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString();
            }

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Digital clock

    What you've got is fine if you want to use the date and time formats specified in the current regional settings, although the following is a bit more succinct:
    C# Code:
    1. lblDateTime.Text = String.Format("{0:d} {0:T}", DateTime.Now);
    On a different note, can I suggest some consistency in your variable names? If you're going to name a Label "lblDateTime" then surely you should name the Timer "tmrClock". If you're going to name the Timer "TimerClock" then surely you should name the Label "LabelDateTime". Frankly, I think Hungarian notation is pointless and I would name them "clockLabel" and "clockTimer".
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Digital clock

    Thanks JM and thanks for that suggestion. I'll put that in mind. Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width