-
13-03-2011, 12:33 PM #1Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Thiết lập thời gian hệ thống trong lập trình C#?
Chào các bạn, có thể cho mình xin đoạn code có chức năng thay đổi giờ hệ thống sử dụng code C# được không, mình cũng có tham khảo 1 số cách nhưng không được.
class Tester
{
[System.Runtime.InteropServices.DllImport("kernel32 ", SetLastError =
true)]
private static extern bool GetSystemTime(out SYSTEMTIME systemTime);
[System.Runtime.InteropServices.DllImport("kernel32 ", SetLastError =
true)]
private static extern bool SetSystemTime(ref SYSTEMTIME systemTime);
struct SYSTEMTIME {
internal short wYear;
internal short wMonth;
internal short wDayOfWeek;
internal short wDay;
internal short wHour;
internal short wMinute;
internal short wSecond;
internal short wMilliseconds;
}
static void Main()
{
SYSTEMTIME st;
if(GetSystemTime(out st))
{
st.wHour = 13; //Beware SYSTEMTIME is in UTC time format!!!!!
if(SetSystemTime(ref st))
Console.WriteLine("success");
else
Console.WriteLine(System.Runtime.InteropServices.M arshal.GetLastWin32Error());
}
else
Console.WriteLine("GetSystemTime failed: {0}",
System.Runtime.InteropServices.Marshal.GetLastWin3 2Error());
}
}
View more random threads:
- Tại sao ở các cty việt nam chậm ứng dụng các công nghệ mới?
- Thao tác với hệ thống bằng C#
- so sánh từng số trong xâu trong lập trình C#?
- từ điển anh việt viết bằng c# sử dụng danh sách liên kết đơn?
- Xử lý biến dạng datetime trong SQL 05 và C#
- Làm sao để cài đặt sự kiện trên thanh scorllbar của webbrowser control
- Dòng CheckForIllegalCrossThreadCalls = false; có tác dụng gì?
- Đường dẫn động trong C#.net
- Convert Database từ FoxPro sang Oracle
- Kooking API trong C# như thế nào?
-
14-03-2011, 10:21 AM #2Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Gửi bởi baothanh07
-
14-03-2011, 10:54 AM #3Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
http://www.geekpedia.com/code117_Get...-And-Time.html
-
14-03-2011, 11:38 AM #4Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Gửi bởi qanlh_soft
Mã:class LocalTimeManager { [DllImport("kernel32.dll")] private extern static void GetLocalTime(ref SYSTEMTIME lpSystemTime); [DllImport("kernel32.dll")] private extern static uint SetLocalTime(ref SYSTEMTIME lpSystemTime); private struct SYSTEMTIME { public ushort wYear; public ushort wMonth; public ushort wDayOfWeek; public ushort wDay; public ushort wHour; public ushort wMinute; public ushort wSecond; public ushort wMilliseconds; } public void GetTime() { // Call the native GetSystemTime method // with the defined structure. SYSTEMTIME stime = new SYSTEMTIME(); GetLocalTime(ref stime); // Show the current time. MessageBox.Show("Current Time: " + stime.wHour.ToString() + ":" + stime.wMinute.ToString()); } public void SetTime() { // Call the native GetSystemTime method // with the defined structure. SYSTEMTIME systime = new SYSTEMTIME(); GetLocalTime(ref systime); // Set the system clock ahead one hour. systime.wHour = (ushort)(systime.wHour + 1 % 24); SetLocalTime(ref systime); MessageBox.Show("New time: " + systime.wHour.ToString() + ":" + systime.wMinute.ToString()); } }
-
14-03-2011, 06:59 PM #5Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Bạn gõ tương tự như vầy do mình mới cài lại máy chưa cài VS:
System.dianotics.process.start("cmd.exe","time 12:00");
Với sự đa dạng và phong phú về mẫu mã và giá cả, choxeonline.vn hứa hẹn sẽ là địa chỉ tin cậy cho những ai đang tìm kiếm chiếc xe ô tô ưng ý. Từ những mẫu xe hạng sang đến những chiếc xe gia đình...
Khám Phá Đa Dạng Sản Phẩm Xe Ô Tô...