本文整理汇总了C#中SYSTEMTIME类的典型用法代码示例。如果您正苦于以下问题:C# SYSTEMTIME类的具体用法?C# SYSTEMTIME怎么用?C# SYSTEMTIME使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SYSTEMTIME类属于命名空间,在下文中一共展示了SYSTEMTIME类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTime
private void GetTime()
{
SYSTEMTIME stime = new SYSTEMTIME();
GetSystemTime(out stime);
//labTime.Text = "Current Time:" + stime.wYear.ToString() + "/" + stime.wMonth.ToString() + "/" + stime.wDay.ToString() + " " + stime.wHour.ToString() +":"+ stime.wMinute.ToString() +":"+ stime.wSecond.ToString();
//lblError.Text = DateTime.Now.ToString("yyyyMMdd");
}
示例2: Main
static void Main(string[] args)
{
TIME_ZONE_INFORMATION tz = new TIME_ZONE_INFORMATION();
GetTimeZoneInformation(ref tz);
string s = args[0];
System.Globalization.DateTimeFormatInfo dtfi =
new System.Globalization.DateTimeFormatInfo();
dtfi.FullDateTimePattern = "dd/MM/yyyy HH:mm:ss zz";
dtfi.DateSeparator = "/";
dtfi.TimeSeparator = ":";
DateTime dt =
DateTime.Parse(s, dtfi);
SYSTEMTIME time = new SYSTEMTIME(dt);
//time.wDay = (ushort)dt.Day;
//time.wHour = (ushort)dt.Hour;
//time.wDayOfWeek = (ushort)dt.DayOfWeek;
//time.wMilliseconds = (ushort)dt.Millisecond;
//time.wMinute = (ushort)dt.Minute;
//time.wMonth = (ushort)dt.Month;
//time.wSecond = (ushort)dt.Second;
//time.wYear = (ushort)dt.Year;
SetSystemTime(ref time);
}
示例3: Main
private static void Main(string[] args)
{
if (args.Length == 5)
{
var time = new SYSTEMTIME
{
wDay = ushort.Parse(args[0]),
wMonth = ushort.Parse(args[1]),
wYear = ushort.Parse(args[2]),
wHour = ushort.Parse(args[3]),
wMinute = ushort.Parse(args[4])
};
SetTime(time);
return;
}
if (File.Exists("date.txt"))
{
var tr = new StreamReader("date.txt");
string dateString = tr.ReadLine();
if (dateString != null)
{
dateString = dateString.Trim();
DateTime convertedDate = DateTime.Parse(dateString);
SetTime(convertedDate);
}
}
else
{
SetTime(1, 1, 2012, 12, 00);
}
}
示例4: Main
static void Main(string[] args)
{
if (args.Length == 0 || (new string[] { "help", "--help", "/?" }).Contains(args[0]))
{
System.Console.WriteLine("Give as the only parameter the time difference in hours. For example \"SetClock.exe -2\" moves the clock two hours backwards.");
return;
}
double delta = 0;
try
{
delta = Convert.ToDouble(args[0]);
}
catch
{
System.Console.WriteLine("Error converting input parameter to time difference.");
return;
}
var newDateTime = DateTime.Now.ToUniversalTime().AddHours(delta);
var newSystemTime = new SYSTEMTIME();
newSystemTime.wYear = Convert.ToInt16(newDateTime.Year);
newSystemTime.wMonth = Convert.ToInt16(newDateTime.Month);
newSystemTime.wDay = Convert.ToInt16(newDateTime.Day);
newSystemTime.wDayOfWeek = Convert.ToInt16(newDateTime.DayOfWeek);
newSystemTime.wHour = Convert.ToInt16(newDateTime.Hour);
newSystemTime.wMinute = Convert.ToInt16(newDateTime.Minute);
newSystemTime.wSecond = Convert.ToInt16(newDateTime.Second);
newSystemTime.wMilliseconds = Convert.ToInt16(newDateTime.Millisecond);
SetSystemTime(ref newSystemTime);
}
示例5: SetTime
public static void SetTime(SYSTEMTIME time)
{
if (!SetLocalTime(ref time))
{
// The native function call failed, so throw an exception
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
示例6: ChangeDateDown
private void ChangeDateDown(int numDays)
{
DateTime t = DateTime.Now.AddDays(-1);
DateTime h = DateTime.Now.AddHours(0);
SYSTEMTIME st = new SYSTEMTIME();
st.FromDateTime(t);
SetSystemTime(ref st);
}
示例7: GetTime
/// <summary>
/// Gets current system time.
/// </summary>
/// <returns></returns>
public static DateTime GetTime()
{
// Call the native GetSystemTime method
// with the defined structure.
SYSTEMTIME stime = new SYSTEMTIME();
GetSystemTime(ref stime);
var utc = new DateTime(stime.wYear, stime.wMonth, stime.wDay, stime.wHour, stime.wMinute, stime.wSecond, stime.wMilliseconds, DateTimeKind.Utc);
return utc.ToLocalTime();
}
示例8: SetSystemTime
// SYSTEMTIME�\����
//
// ABSTRACT : DateTime�R���g���[���Ƀ��b�Z�[�W�𑗂�
//
public static System.IntPtr SetSystemTime(
int pid , // �^�[�Q�b�g�̃v���Z�XID
System.IntPtr hDateTime , // DATETIME�R���g���[���n���h��
SYSTEMTIME sysTime )
{
System.IntPtr hAccess;
System.IntPtr mem;
System.IntPtr result;
GCHandle gctemp;
int n;
hAccess = InterProcess.OpenProcess(
InterProcess.PROCESS_VM_OPERATION |
InterProcess.PROCESS_VM_READ |
InterProcess.PROCESS_VM_WRITE ,
0 ,
pid );
mem = InterProcess.VirtualAllocEx(
hAccess ,
(System.IntPtr)0 ,
4096 ,
InterProcess.MEM_COMMIT |
InterProcess.MEM_RESERVE ,
InterProcess.PAGE_READWRITE );
// �\���̂�v���Z�X�ɏ�������
gctemp = GCHandle.Alloc( sysTime, GCHandleType.Pinned );
System.IntPtr a = gctemp.AddrOfPinnedObject();
InterProcess.WriteProcessMemory(
hAccess ,
mem ,
a ,
Marshal.SizeOf( sysTime ),
out n );
result = Window.SendMessage(
hDateTime ,
DTM_SETSYSTEMTIME ,
System.IntPtr.Zero , // GDT_VALID
mem );
gctemp.Free();
InterProcess.VirtualFreeEx( hAccess, mem, 4096, InterProcess.MEM_RELEASE );
return result;
}
示例9: SetLocalTime
public static void SetLocalTime(DateTime time)
{
var newTime = new SYSTEMTIME
{
wYear = (ushort)time.Year,
wMonth = (ushort)time.Month,
wDay = (ushort)time.Day,
wHour = (ushort)time.Hour,
wMinute = (ushort)time.Minute,
wSecond = (ushort)time.Second,
wMilliseconds = (ushort)time.Millisecond
};
SetLocalTime(ref newTime);
}
示例10: SetTime
/// <summary>
/// Sets current system time.
/// </summary>
/// <param name="dateTime">Time to set as current system time.</param>
public static void SetTime(DateTime dateTime)
{
dateTime = dateTime.ToUniversalTime();
SYSTEMTIME stime = new SYSTEMTIME()
{
wYear = (ushort)dateTime.Year,
wMonth = (ushort)dateTime.Month,
wDay = (ushort)dateTime.Day,
wHour = (ushort)dateTime.Hour,
wMinute = (ushort)dateTime.Minute,
wSecond = (ushort)dateTime.Second,
wMilliseconds = (ushort)dateTime.Millisecond
};
SetSystemTime(ref stime);
}
示例11: SetTime
///<summary>Set the windows system time.</summary>
public static void SetTime(DateTime newTime) {
// Call the native SetLocalTime method
// with the defined structure.
SYSTEMTIME systime=new SYSTEMTIME();
systime.wYear=(ushort)newTime.Year;
systime.wMonth=(ushort)newTime.Month;
systime.wDayOfWeek=(ushort)newTime.DayOfWeek;
systime.wDay=(ushort)newTime.Day;
systime.wHour=(ushort)newTime.Hour;
systime.wMinute=(ushort)newTime.Minute;
systime.wSecond=(ushort)newTime.Second;
systime.wMilliseconds=(ushort)newTime.Millisecond;
SetLocalTime(ref systime);
string messageText="System date and time set to: "+newTime.ToString("MM/dd/yyyy hh:mm:ss.fff tt")+".";
EventLog.WriteEntry("OpenDental",messageText,EventLogEntryType.Information);
}
示例12: DigitalClockDisplay
public DigitalClockDisplay(bool is24Hour, bool suppressExtra)
{
f24Hour = is24Hour;
fSuppress = suppressExtra;
fSegmentedNumber = new SegmentedNumber();
ptColon = new Point[2][];
ptColon[0] = new Point[] { new Point(2, 21), new Point(6, 17), new Point(10, 21), new Point(6, 25) };
ptColon[1] = new Point[] { new Point(2, 51), new Point(6, 47), new Point(10, 51), new Point(6, 55) };
fcolonPolies = new PolygonG[2];
fcolonPolies[0] = new PolygonG(ptColon[0]);
fcolonPolies[1] = new PolygonG(ptColon[1]);
fLastTime = new SYSTEMTIME();
fThisTime = new SYSTEMTIME();
}
示例13: SetTime
public static void SetTime(DateTime dt)
{
// Call the native GetSystemTime method
// with the defined structure.
SYSTEMTIME systime = new SYSTEMTIME();
//GetSystemTime(ref systime);
systime.wDay = (ushort)dt.Day;
systime.wMonth = (ushort)dt.Month;
systime.wYear = (ushort)dt.Year;
systime.wHour = (ushort)dt.Hour;
systime.wMinute = (ushort)dt.Minute;
systime.wSecond = (ushort)dt.Second;
// Set the system clock ahead one hour.
//systime.wHour = (ushort)(systime.wHour + 1 % 24);
SetSystemTime(ref systime);
System.Diagnostics.Debug.WriteLine(string.Format("New time: " + systime.wHour.ToString() + ":"
+ systime.wMinute.ToString()+"\r\n"));
}
示例14: BLUETOOTH_DEVICE_INFO
public BLUETOOTH_DEVICE_INFO(long address)
{
dwSize = 560;
this.Address = address;
ulClassofDevice = 0;
fConnected = false;
fRemembered = false;
fAuthenticated = false;
#if WinXP
stLastSeen = new SYSTEMTIME();
stLastUsed = new SYSTEMTIME();
// The size is much smaller on CE (no times and string not inline) it
// appears to ignore the bad dwSize value. So don't check this on CF.
System.Diagnostics.Debug.Assert(Marshal.SizeOf(typeof(BLUETOOTH_DEVICE_INFO)) == dwSize, "BLUETOOTH_DEVICE_INFO SizeOf == dwSize");
#endif
szName = "";
}
示例15:
int IVsSolutionEventsProjectUpgrade.OnAfterUpgradeProject(IVsHierarchy pHierarchy, uint fUpgradeFlag, string bstrCopyLocation, SYSTEMTIME stUpgradeTime, IVsUpgradeLogger pLogger)
{
Debug.Assert(pHierarchy != null);
Project upgradedProject = VsUtility.GetProjectFromHierarchy(pHierarchy);
if (upgradedProject != null)
{
IList<IPackage> packagesToBeReinstalled = ProjectRetargetingUtility.GetPackagesToBeReinstalled(upgradedProject);
if (!packagesToBeReinstalled.IsEmpty())
{
pLogger.LogMessage((int)__VSUL_ERRORLEVEL.VSUL_ERROR, upgradedProject.Name, upgradedProject.Name,
String.Format(CultureInfo.CurrentCulture, Resources.ProjectUpgradeAndRetargetErrorMessage, String.Join(", ", packagesToBeReinstalled.Select(p => p.Id))));
}
}
return VSConstants.S_OK;
}