应用程序在状态栏展示时间(C#)

 

 

 

  private DispatcherTimer _timer;

 

 

   private void SetTimeElaspInStatusBar()

        {

            try

            {

               

                _timer = new DispatcherTimer();

                _timer.Tick += (sender, e) =>

                {

                    DateTime dtNow = DateTime.Now;

                    TimeSpan interval = dtNow - _enterSystemTime;

 

                    this.barElapsedTime.Content = null;

 

                    #region

 

                    TimeZoneInfo currentTimeZone = TimeZoneUtil.GetLocalTimeZone();

                    if (currentTimeZone != null)

                    {

                        string str = currentTimeZone.Id;

 

                        this.barElapsedTime.Content += "     Local Time(" + str + " )"

                            + ": "

                            + dtNow.ToString("MM/dd/yyyy HH:mm:ss");

 

                        //DateTimeUtil.ConvertToUniversalTimeString(this._enterSystemTime, "MM/dd/yyyy HH:mm:ss");

                    }

 

                    //this.barElapsedTime.Content += "     UTC Time : "

                    //    + DateTimeUtil.ConvertToUniversalTimeString(dtNow, "MM/dd/yyyy HH:mm:ss");

 

                    DateTime? dtUTC =TimeZoneUtil.ConvertTimeToUTC(dtNow);

                

                    if (dtUTC != null)

                    {

                        this.barElapsedTime.Content += "     UTC Time : "

                            +((DateTime)dtUTC).ToString("MM/dd/yyyy HH:mm:ss");

                    }

 

 

                    ////Convert To "Central America Standard Time"

                    //DateTime? dtUSCenter = TimeZoneUtil.ConvertFromUTC((DateTime)dtUTC, "Central America Standard Time");

 

                    //if (dtUSCenter != null)

                    //{

 

                    //    this.barElapsedTime.Content += "     UTC Time to  Central America Standard Time: "

                    //                               + ((DateTime)dtUSCenter).ToString("MM/dd/yyyy HH:mm:ss");

                    //}

 

                    #endregion

 

                    this.barElapsedTime.Content += "        Elapsed Time: " + (interval.Days > 0 ? interval.Days + " day(s) " : "") +

                       new DateTime(1900, 1, 1, interval.Hours, interval.Minutes, interval.Seconds).ToString("HH:mm:ss");

 

                    //

                    if (EventBinder.SystemTimeOutCheck.IsCheckTimeOut)

                    {

                        EventBinder.SystemTimeOutCheck.Check();

                    }

                   // SystemThreadStarter.StartGetUrlThread();

                };

                _timer.Interval = TimeSpan.FromSeconds(1);

                _timer.Start();

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

        }

 

posted @ 2014-01-23 12:06  quietwalk  阅读(1213)  评论(0编辑  收藏  举报