English 中文(简体)
数字锁:
原标题:Digital clock -
  • 时间:2011-05-08 05:13:52
  •  标签:
  • c#
  • wpf

我要展示一个数字钟。 这里,我不得不在24小时格式的正文中显示时间,我知道如何转换到12小时。

DispatcherTimer timerdigital;

    public MainWindow()
    {
        this.InitializeComponent();
        //StartTimer(null, null);

        timerdigital = new DispatcherTimer();
        timerdigital.Interval = TimeSpan.FromSeconds(1.0);
        timerdigital.Start();
        timerdigital.Tick += new EventHandler(delegate(object s, EventArgs a)
        {
            tbDigital.Text = "" + DateTime.Now.Hour + ":"
          + DateTime.Now.Minute + ":"
          + DateTime.Now.Second;


        });

感谢

问题回答

不知道数字式显示,但为了从24小时转换为12小时24小时,最容易的方法是使用日记格式:

timerdigital.Tick += new EventHandler(delegate(object s, EventArgs a)
        {
            tbDigital.Text = DateTime.Now.ToString("hh:mm:ss tt");
        });

<代码>h为12小时格式的小时数,<>mm/code>为分钟,s为秒钟,<>>为

See more about Date and Time format strings here.

Here is a nice ready to use source code for wpf:
http://www.codeproject.com/KB/WPF/digitalclock.aspx
About the 12/24 hour format:

 int smallhour = (Hour > 12) ? Hour - 12 : Hour;




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...