Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone

I want to set the windows CE time by C# code.

It seems that I need to use some dlls.

I will appreciate any help (code samples)

TnX
Posted
Comments
[no name] 31-Jul-13 1:31am    
What is that "CE time"..???
Behno0o0oD 31-Jul-13 2:02am    
windows compact edition time

1 solution

Yes you're right - you need the core.dll

C#
//This will be the method you need to set the system time
[DllImport("coredll.dll", SetLastError=true)]
static extern bool SetLocalTime(ref SYSTEMTIME lpSystemTime);

//This is the object you need to fill before you use SetLocalTime
public struct SYSTEMTIME
{
     public short year;
     public short month;
     public short dayOfWeek;
     public short day;
     public short hour;
     public short minute;
     public short second;
     public short milliseconds;
}

//And this is the final method to execute
public static void SetSystemDateTime(DateTime dt)
{
     SYSTEMTIME systime;
     systime.year = (short)dt.Year;
     systime.month = (short)dt.Month;
     systime.day = (short)dt.Day;

     systime.hour = (short)dt.Hour;
     systime.minute = (short)dt.Minute;
     systime.second = (short)dt.Second;
     systime.milliseconds = (short)dt.Millisecond;
     systime.dayOfWeek = (short)dt.DayOfWeek;

     SetLocalTime(systime);
}
 
Share this answer
 
Comments
Behno0o0oD 31-Jul-13 2:03am    
How Can I use this code?
I copied them to a class, but there are some errors.tnx
midnight_ 31-Jul-13 2:04am    
What kind of errors?
Behno0o0oD 31-Jul-13 2:09am    
The best overloaded method match for 'SmartDeviceProject1.Form1.SetLocalTime(ref SmartDeviceProject1.Form1.SYSTEMTIME)' has some invalid arguments
Behno0o0oD 31-Jul-13 2:10am    
SetLocalTime(ref systime);

it works;)
midnight_ 31-Jul-13 5:07am    
Sorry, I forgot to add it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900