If you just want to get the system time -> DateTime.Now is your friend, but If you want to SET the system clock, you can do it like this: (I use this methods in a .NET CF application, the example code was taken from MSDN)
using System;
using System.Runtime.InteropServices;
namespace SetSystemTime
{
class Program
{
[DllImport("kernel32.dll")]
private extern static uint SetSystemTime(ref SYSTEMTIME lpSystemTime);
[DllImport("kernel32.dll")]
private extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);
[StructLayout(LayoutKind.Sequential)]
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;
}
static void Main(string[] args)
{
SYSTEMTIME timeNow = new SYSTEMTIME();
GetSystemTime(ref timeNow);
Console.WriteLine("Now: {0}:{1}:{2}", timeNow.wHour, timeNow.wMinute, timeNow.wSecond);
SYSTEMTIME timeNew = new SYSTEMTIME();
GetSystemTime(ref timeNew);
timeNew.wHour = (ushort)(timeNew.wHour + 1 % 24);
SetSystemTime(ref timeNew);
Console.WriteLine("New: {0}:{1}:{2}", timeNew.wHour, timeNew.wMinute, timeNew.wSecond);
}
}
}