C Thiết lập ngày giờ hệ thống
Số trang: 2
Loại file: doc
Dung lượng: 55.50 KB
Lượt xem: 8
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Đoạn mã C# code snippet sau đây sử dụng mã không quản để lấy về thời gian hiện tạicủa hệ điều hành Windows, đồng thời cũng cho phép bạn thiết lập lại thời gian cụ thểnào đó tùy ý. using System; using System.Collections.Generic; usingSystem.ComponentModel;...
Nội dung trích xuất từ tài liệu:
C Thiết lập ngày giờ hệ thốngC Thiết lập ngày giờ hệ thốngCập nhật: 26/8/2008 với no commentsĐoạn mã C# code snippet sau đây sử dụng mã không quản để lấy về thời gian hiện tạicủa hệ điều hành Windows, đồng thời cũng cho phép bạn thiết lập lại thời gian cụ thểnào đó tùy ý. using System; using System.Collections.Generic; usingSystem.ComponentModel;...Đoạn mã C# code snippet sau đây sử dụng mã không quản để lấy về thời gian hiện tạicủa hệ điều hành Windows, đồng thời cũng cho phép bạn thiết lập lại thời gian cụ thểnào đó tùy ý.view plainprint? 1. 2. using System; 3. using System.Collections.Generic; 4. using System.ComponentModel; 5. using System.Data; 6. using System.Windows.Forms; 7. using System.Runtime.InteropServices; 8. namespace Sample 9. { 10. public partial class Form1 : Form 11. { 12. public Form1() 13. { 14. InitializeComponent(); 15. } 16. public struct SystemTime 17. { 18. public ushort Year; 19. public ushort Month; 20. public ushort DayOfWeek; 21. public ushort Day; 22. public ushort Hour; 23. public ushort Minute; 24. public ushort Second; 25. public ushort Millisecond; 26. }; 27. [DllImport(kernel32.dll, EntryPoint = GetSystemTime, SetLastError = tr ue)] 28. public extern static void Win32GetSystemTime(ref SystemTime sysTime); 29. [DllImport(kernel32.dll, EntryPoint = SetSystemTime, SetLastError = tr ue)] 30. public extern static bool Win32SetSystemTime(ref SystemTime sysTime);31. private void button1_Click(object sender, EventArgs e)32. {33. // Set system date and time34. SystemTime updatedTime = new SystemTime();35. updatedTime.Year = (ushort)2008;36. updatedTime.Month = (ushort)4;37. updatedTime.Day = (ushort)23;38. // UTC time; it will be modified according to the regional settings of the ta rget computer so the actual hour might differ39. updatedTime.Hour = (ushort)10;40. updatedTime.Minute = (ushort)0;41. updatedTime.Second = (ushort)0;42. // Call the unmanaged function that sets the new date and time instantly43. Win32SetSystemTime(ref updatedTime);44. // Retrieve the current system date and time45. SystemTime currTime = new SystemTime();46. Win32GetSystemTime(ref currTime);47. // You can now use the struct to retrieve the date and time48. MessageBox.Show(Its + currTime.Hour + oclock. Do you know whe re your C# code is?);49. }50. }51. }
Nội dung trích xuất từ tài liệu:
C Thiết lập ngày giờ hệ thốngC Thiết lập ngày giờ hệ thốngCập nhật: 26/8/2008 với no commentsĐoạn mã C# code snippet sau đây sử dụng mã không quản để lấy về thời gian hiện tạicủa hệ điều hành Windows, đồng thời cũng cho phép bạn thiết lập lại thời gian cụ thểnào đó tùy ý. using System; using System.Collections.Generic; usingSystem.ComponentModel;...Đoạn mã C# code snippet sau đây sử dụng mã không quản để lấy về thời gian hiện tạicủa hệ điều hành Windows, đồng thời cũng cho phép bạn thiết lập lại thời gian cụ thểnào đó tùy ý.view plainprint? 1. 2. using System; 3. using System.Collections.Generic; 4. using System.ComponentModel; 5. using System.Data; 6. using System.Windows.Forms; 7. using System.Runtime.InteropServices; 8. namespace Sample 9. { 10. public partial class Form1 : Form 11. { 12. public Form1() 13. { 14. InitializeComponent(); 15. } 16. public struct SystemTime 17. { 18. public ushort Year; 19. public ushort Month; 20. public ushort DayOfWeek; 21. public ushort Day; 22. public ushort Hour; 23. public ushort Minute; 24. public ushort Second; 25. public ushort Millisecond; 26. }; 27. [DllImport(kernel32.dll, EntryPoint = GetSystemTime, SetLastError = tr ue)] 28. public extern static void Win32GetSystemTime(ref SystemTime sysTime); 29. [DllImport(kernel32.dll, EntryPoint = SetSystemTime, SetLastError = tr ue)] 30. public extern static bool Win32SetSystemTime(ref SystemTime sysTime);31. private void button1_Click(object sender, EventArgs e)32. {33. // Set system date and time34. SystemTime updatedTime = new SystemTime();35. updatedTime.Year = (ushort)2008;36. updatedTime.Month = (ushort)4;37. updatedTime.Day = (ushort)23;38. // UTC time; it will be modified according to the regional settings of the ta rget computer so the actual hour might differ39. updatedTime.Hour = (ushort)10;40. updatedTime.Minute = (ushort)0;41. updatedTime.Second = (ushort)0;42. // Call the unmanaged function that sets the new date and time instantly43. Win32SetSystemTime(ref updatedTime);44. // Retrieve the current system date and time45. SystemTime currTime = new SystemTime();46. Win32GetSystemTime(ref currTime);47. // You can now use the struct to retrieve the date and time48. MessageBox.Show(Its + currTime.Hour + oclock. Do you know whe re your C# code is?);49. }50. }51. }
Tìm kiếm theo từ khóa liên quan:
thủ thuật máy tính công nghệ thông tin tin học quản trị mạng computer networkTài liệu liên quan:
-
52 trang 433 1 0
-
24 trang 359 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 320 0 0 -
Làm việc với Read Only Domain Controllers
20 trang 310 0 0 -
74 trang 303 0 0
-
96 trang 297 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 291 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 285 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 277 0 0 -
Tài liệu hướng dẫn sử dụng thư điện tử tài nguyên và môi trường
72 trang 270 0 0