Tuesday, July 30, 2019

Setting time format

https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings


if you want a constantly updating time, use a Timer
System.Timers.Timer timer = new System.Timers.Timer(1000);
timer.Elapsed += TimerElapsed;
timer.AutoReset = true;
timer.Start();

private void TimerElapsed(Object source, ElapsedEventArgs e)
{
    myLabel.Text = e.SignalTime.ToString();
}
if you want to use databinding, have your elapsed event update the ViewModel property that your label is bound to instead of directly updating the Label

  • If you type string currentDate = DateTime.Now.ToString()

No comments:

Post a Comment