Danh mục

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    
10.10.2023

Hỗ trợ phí lưu trữ khi tải xuống: miễn phí Tải xuống file đầy đủ (2 trang) 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. }

Tài liệu được xem nhiều: