Guest User

Untitled

a guest
Nov 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. private void Timer_Tick(object sender,EventArgs e)
  2. {
  3. //lblTime.Content = DateTime.Now.ToLongTimeString();
  4. //lblTime.Content = DateTime.Now.ToString("HH:mm:ss:fff");
  5.  
  6. //milliseconds++;
  7. //if (milliseconds >= 1000) {
  8. // sec++;
  9. // milliseconds = 0;
  10. //}
  11. //if (sec == 60) {
  12. // min++;
  13. // sec = 0;
  14. //}
  15. //lblTime.Content = string.Format("{0:00}:{1:00}:{2:D3}",min,sec,milliseconds);
  16.  
  17.  
  18. milliseconds += 15.560;
  19.  
  20. if (milliseconds >= 1000) {
  21. milliseconds = 0;
  22. sec++;
  23.  
  24. if (sec >= 60) {
  25. sec = 0;
  26. min++;
  27. }
  28. }
  29.  
  30. lblTime.Content = min.ToString("00") + ":" + sec.ToString("00") + ":" +
  31. milliseconds.ToString("000").Substring(0,3);
  32.  
  33. //lblTime.Content = String.Format("{0:00}:{1:00}:{2:000}", timer.Interval.Minutes, timer.Interval.Seconds, timer.Interval.Milliseconds);
  34. }
  35.  
  36. private void Start(object sender,EventArgs e)
  37. {
  38. timer.Interval = TimeSpan.FromMilliseconds(1);
  39. timer.Tick += Timer_Tick;
  40. timer.Start();
  41. }
  42.  
  43. public partial class MainWindow :Window
  44. {
  45. DispatcherTimer timer = new DispatcherTimer();
  46.  
  47. int min = 0, sec = 0;
  48. double milliseconds = 0;
  49.  
  50. public MainWindow()
  51. {
  52. InitializeComponent();
  53. }
  54.  
  55. private void Timer_Tick(object sender,EventArgs e)
  56. {
  57. //lblTime.Content = DateTime.Now.ToLongTimeString();
  58. //lblTime.Content = DateTime.Now.ToString("HH:mm:ss:fff");
  59.  
  60. //milliseconds++;
  61. //if (milliseconds >= 1000) {
  62. // sec++;
  63. // milliseconds = 0;
  64. //}
  65. //if (sec == 60) {
  66. // min++;
  67. // sec = 0;
  68. //}
  69. //lblTime.Content = string.Format("{0:00}:{1:00}:{2:D3}",min,sec,milliseconds);
  70.  
  71.  
  72. milliseconds += 15.560;
  73.  
  74. if (milliseconds >= 1000) {
  75. milliseconds = 0;
  76. sec++;
  77.  
  78. if (sec >= 60) {
  79. sec = 0;
  80. min++;
  81. }
  82. }
  83.  
  84. lblTime.Content = min.ToString("00") + ":" + sec.ToString("00") + ":" +
  85. milliseconds.ToString("000").Substring(0,3);
  86.  
  87. //lblTime.Content = String.Format("{0:00}:{1:00}:{2:000}", timer.Interval.Minutes, timer.Interval.Seconds, timer.Interval.Milliseconds);
  88. }
  89.  
  90. private void Start(object sender,EventArgs e)
  91. {
  92. timer.Interval = TimeSpan.FromMilliseconds(1);
  93. timer.Tick += Timer_Tick;
  94. timer.Start();
  95. }
  96. }
  97.  
  98. Stopwatch stopwatch = new Stopwatch();
  99.  
  100. stopwatch.Start();
  101. for (; ;)
  102. {
  103. Console.WriteLine(stopwatch.Elapsed);
  104. }
Add Comment
Please, Sign In to add comment