本文整理汇总了C#中SystemTime类的典型用法代码示例。如果您正苦于以下问题:C# SystemTime类的具体用法?C# SystemTime怎么用?C# SystemTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SystemTime类属于命名空间,在下文中一共展示了SystemTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string [] args)
{
try
{
SystemTime time = new SystemTime();
GetSystemTime(ref time);
Console.WriteLine("Year : " +time.year);
Console.WriteLine("month : " +time.month);
Console.WriteLine("Days of Week : " +time.daysofweek);
Console.WriteLine("Day : " + time.day);
Console.WriteLine("Hours : " + time.hour);
Console.WriteLine("minutes : " + time.minute);
Console.WriteLine("Seconds : " + time.seconds);
Console.WriteLine("milliseconds : " + time.milliseconds);
time.year += 1;
SetSystemTime(ref time);
Console.WriteLine("new year " + time.year);
}
catch(Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
}
}
示例2: Main
static void Main(string[] args)
{
SystemTime t = new SystemTime();
GetSystemTime(t);
Console.WriteLine("{0}:{1}:{2}.{3}", t.Hour, t.Minute, t.Second, t.Milliseconds);
Console.ReadLine();
}
示例3: GetDateTime
public static DateTime GetDateTime(int sysTime)
{
IntPtr pSysTime = new IntPtr(sysTime);
SystemTime sTime = new SystemTime();
sTime = (SystemTime) Marshal.PtrToStructure(pSysTime, typeof (SystemTime));
return sTime.ToDateTime();
}
示例4: SetSystemTime
public static void SetSystemTime(DateTime dateTime)
{
// Set system date and time
SystemTime updatedTime = new SystemTime();
updatedTime.Year = (ushort)dateTime.Year;
updatedTime.Month = (ushort)dateTime.Month;
updatedTime.Day = (ushort)dateTime.Day;
// UTC time; it will be modified according to the regional settings of the target computer so the actual hour might differ
updatedTime.Hour = (ushort)dateTime.Hour;
updatedTime.Minute = (ushort)dateTime.Minute;
updatedTime.Second = (ushort)dateTime.Second;
// Call the unmanaged function that sets the new date and time instantly
Win32SetSystemTime(ref updatedTime);
}
示例5: SetLocalTimeByDateTime
public static bool SetLocalTimeByDateTime(System.DateTime dt)
{
bool flag = false;
SystemTime timeData = new SystemTime();
timeData.wYear = (ushort)dt.Year;
timeData.wMonth = (ushort)dt.Month;
timeData.wDay = (ushort)dt.Day;
timeData.wHour = (ushort)dt.Hour;
timeData.wMinute = (ushort)dt.Minute;
timeData.wSecond = (ushort)dt.Second;
flag = SetLocalTime(ref timeData);
return flag;
}
示例6: SetLocalTime
public static int SetLocalTime(DateTime datetime)
{
SystemTime systNew = new SystemTime();
// 设置属性
systNew.wDay = (short)datetime.Day;
systNew.wMonth = (short)datetime.Month;
systNew.wYear = (short)datetime.Year;
systNew.wHour = (short)datetime.Hour;
systNew.wMinute = (short)datetime.Minute;
systNew.wSecond = (short)datetime.Second;
systNew.wMilliseconds = (short)datetime.Millisecond;
// 调用API,更新系统时间
return SetLocalTime(ref systNew);
}
示例7: Main
static void Main()
{
Console.WriteLine("It shows system time columns:");
var t1 = new SystemTime {Name = "tom"};
t1.Save();
var t2 = SystemTime.FindById(t1.Id);
Console.WriteLine("1) => {0}", t2);
Thread.Sleep(2000);
t1.Save();
var t3 = SystemTime.FindById(t1.Id);
Console.WriteLine("2) => {0}", t3);
}
示例8: Check_Before_Login
public int Check_Before_Login()
{
try
{
OleDbConnection conn = new OleDbConnection(strConAll);
string selectcmd = "select sysdate from dual";
OleDbCommand comm = new OleDbCommand(selectcmd, conn);
OleDbDataAdapter da = new OleDbDataAdapter(comm);
DataSet ds = new DataSet();
da.Fill(ds);
//System.DateTime SQLServer_time = (System.DateTime)comm.ExecuteScalar();
System.DateTime SQLServer_time = (System.DateTime)ds.Tables[0].Rows[0][0];
conn.Close();
//SqlConnection conn = new SqlConnection(strConAll);
//conn.Open();
//SqlCommand scmd = new SqlCommand(selectcmd, conn);
//System.DateTime SQLServer_time = (System.DateTime)scmd.ExecuteScalar();
//conn.Close();
//根据得到的时间日期,来定义时间、日期
SystemTime st = new SystemTime();
st.wYear = (short)SQLServer_time.Year;
st.wDay = (short)SQLServer_time.Day;
st.wMonth = (short)SQLServer_time.Month;
st.wHour = (short)SQLServer_time.Hour;
st.wMinute = (short)SQLServer_time.Minute;
st.wSecond = (short)SQLServer_time.Second;
//修改本地端的时间和日期
Win32API.SetLocalTime(ref st);
return 1;
}
catch
{
MessageBox.Show("服务器可能没启动,请检查以后重新进入! ", "错误 ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return 0;
//Application.Exit();
}
}
示例9: CheckLocalTime
/// <summary>
/// 数据中心校时
/// </summary>
/// <param name="_now"></param>
public static bool CheckLocalTime(DateTime _now)
{
try
{
SystemTime systNew = new SystemTime();
// 设置属性
systNew.wYear = short.Parse(_now.Year.ToString());
systNew.wMonth = short.Parse(_now.Month.ToString());
systNew.wDay = short.Parse(_now.Day.ToString());
systNew.wHour = short.Parse(_now.Hour.ToString());
systNew.wMinute = short.Parse(_now.Minute.ToString());
systNew.wSecond = short.Parse(_now.Second.ToString());
// 调用API,更新系统时间
return SetLocalTime(ref systNew).Equals(1);
}
catch
{
return false;
}
}
示例10: GetRunTimes
public DateTime[] GetRunTimes(DateTime start, DateTime end, uint count = 0)
{
var pstStart = new SystemTime(start);
var pstEnd = new SystemTime(end);
var zero = IntPtr.Zero;
if (_v2Task != null)
_v2Task.GetRunTimes(ref pstStart, ref pstEnd, ref count, ref zero);
else
{
var num = (count > 0 && count <= 0x5a0 ? (ushort)count : (ushort)0x5a0);
_v1Task.GetRunTimes(ref pstStart, ref pstEnd, ref num, ref zero);
count = num;
}
var timeArray = new DateTime[count];
for (var i = 0; i < count; i++)
{
var ptr = new IntPtr(zero.ToInt64() + (i * Marshal.SizeOf(typeof(SystemTime))));
timeArray[i] = (DateTime)((SystemTime)Marshal.PtrToStructure(ptr, typeof(SystemTime)));
}
Marshal.FreeCoTaskMem(zero);
return timeArray;
}
示例11: serverThread
public static unsafe void serverThread()
{
UdpClient udpClient = new UdpClient(SERVER_PORT);
string dataTemplate = "sync ";
while (true)
{
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
string returnData = Encoding.ASCII.GetString(receiveBytes);
if (returnData.IndexOf(dataTemplate) != -1)
{
SystemTime systime = new SystemTime();
LibWrap.GetSystemTime(systime);
int startIndex = dataTemplate.Length;
int allData = returnData.Length;
string dataString = returnData.Substring(startIndex, allData - startIndex);
DateTime data = Convert.ToDateTime(dataString);
systime.Hour = (ushort)data.Hour;
systime.Minute = (ushort)data.Minute;
systime.Second = (ushort)data.Second;
LibWrap.Win32SetSystemTime(systime);
Console.WriteLine("Время синхронизировано!");
break;
}
}
// Console.ReadLine();
}
示例12: FileTimeToSystemTime
public static extern bool FileTimeToSystemTime(
[In] ref long fileTime,
out SystemTime systemTime);
示例13: SetLocalTime
public static extern bool SetLocalTime(ref SystemTime sysTime); //设置本地时
示例14: KbdData
//.........这里部分代码省略.........
foreach (string fname in Directory.GetFiles(dname, "20*.txt"))
{
FileInfo fi = new FileInfo(fname);
Match m = Regex.Match(fi.Name, @"(\d\d\d\d)_(\d\d)_(\d\d).*");
if (m.Success)
{
if ((Convert.ToUInt16(data.Substring(0, 4)) >= Convert.ToUInt16(m.Groups[1].Value)) &&
(Convert.ToUInt16(data.Substring(4, 2)) >= Convert.ToUInt16(m.Groups[2].Value)) &&
(Convert.ToUInt16(data.Substring(6, 2)) >= Convert.ToUInt16(m.Groups[3].Value)) &&
(Convert.ToUInt16(export_start.Substring(0, 4)) <= Convert.ToUInt16(m.Groups[1].Value)) &&
(Convert.ToUInt16(export_start.Substring(4, 2)) <= Convert.ToUInt16(m.Groups[2].Value)) &&
(Convert.ToUInt16(export_start.Substring(6, 2)) <= Convert.ToUInt16(m.Groups[3].Value)))
{
File.Copy(fname, StringResource.udiskdir + "\\" + fi.Name, true);
}
}
}
}
Program.msg.Init(StringResource.str("export_done"));
}
catch
{
Program.msg.Init(StringResource.str("export_fail"));
return;
}
}
if (param == "newtime")
{
if (!Regex.IsMatch(newdate, "^\\d\\d\\d\\d\\d\\d\\d\\d$"))
return;
if (!Regex.IsMatch(data, "^\\d\\d\\d\\d\\d\\d$"))
return;
SystemTime time = new SystemTime();
time.wYear = Convert.ToUInt16(newdate.Substring(0, 4));
time.wMonth = Convert.ToUInt16(newdate.Substring(4, 2));
time.wDay = Convert.ToUInt16(newdate.Substring(6, 2));
time.wHour = Convert.ToUInt16(data.Substring(0, 2));
time.wMinute = Convert.ToUInt16(data.Substring(2, 2));
time.wSecond = Convert.ToUInt16(data.Substring(4, 2));
time.wMiliseconds = 0;
SetLocalTime(ref time);
}
if (param == "newdate")
{
if(data.StartsWith("8")) //input of scale offset
{
string sparam = data.Remove(0, 1);
if (ActionMgr.ConvertToRange(sparam) != ActionMgr.RNG_INVALID)
{
this.Invoke(new Action<string>(enterscale), new string[] { sparam });
}
return;
}
if (data=="00000") //do upgrade
{
Program.Upgrade();
return;
}
if(data == "99999") //current calibration
{
string sparam = data.Remove(0, 1);
RxInfo myrx = Program.lst_rxinfo[Program.mainwnd.selectedRx];
myrx.var.rRs = Program.lst_rsinfo[0].dTValue;
if (myrx.iRRange == ActionMgr.RNG_P001)
myrx.var.iK = 1; //1000:1
示例15: SetSystemTime
public static extern bool SetSystemTime(ref SystemTime sysTime);