亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

在Unity中實(shí)現(xiàn)簡單的偽時(shí)間同步

 更新時(shí)間:2015年03月11日 16:42:04   投稿:hebedich  
這篇文章主要介紹了在Unity中實(shí)現(xiàn)簡單的偽時(shí)間同步,為什么說是偽同步呢,因?yàn)閮H僅是獲取的數(shù)據(jù)庫所在服務(wù)器的系統(tǒng)時(shí)間,分享給大家,有需要的小伙伴可以參考下

在Unity中實(shí)現(xiàn)簡單的偽時(shí)間同步,只是讀取數(shù)據(jù)庫所在電腦的當(dāng)前時(shí)間

復(fù)制代碼 代碼如下:

using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
using System.Data;
using System.Data.SqlClient;
public class ChangeTime
{
    //Kernel32.dll在32位系統(tǒng)和64位系統(tǒng)有區(qū)別,64位系統(tǒng)中需要設(shè)置為以管理員身份運(yùn)行
    [DllImport("Kernel32.dll",SetLastError=true,EntryPoint="SetLocalTime")]
    static extern int SetLocalTime(ref SystemDateTime lpSystemDateTime);
    public static string GetCurrentTimeFromDB()
    {
        string result = "";
        //從數(shù)據(jù)庫中獲取系統(tǒng)當(dāng)前時(shí)間
        //設(shè)置連接字符串
        SqlConnection con = new SqlConnection ("Data Source=192.168.0.1;Initial Catalog=DB;User ID=sa;password=123456");
        SqlCommand cmd = new SqlCommand ();
        cmd.Connection = con;
        cmd.CommandType = System.Data.CommandType.Text;
        //設(shè)置連接語句
        cmd.CommandText = "select getdate()";
        SqlDataAdapter sda = new SqlDataAdapter(cmd);
        //開啟
        sda.SelectCommand.Connection.Open();
        result = sda.SelectCommand.ExecuteScalar().ToString();
        //關(guān)閉
        sda.SelectCommand.Connection.Close();
        return result;
    }
    public static void SetLocalDae(string dateTime)
    {
        System.DateTime date = System.DateTime.Parse(dateTime);
        SystemDateTime sysNew = new SystemDateTime();
        //設(shè)置屬性
        sysNew.tYear = short.Parse(date.Year.ToString());
        sysNew.tMonth = short.Parse(date.Month.ToString());
        sysNew.tDay = short.Parse(date.Day.ToString());
        sysNew.tHour = short.Parse(date.Hour.ToString());
        sysNew.tMinute = short.Parse(date.Minute.ToString());
        sysNew.tSecond = short.Parse(date.Second.ToString());
        //調(diào)用API,更新系統(tǒng)時(shí)間
        SetLocalTime(ref sysNew);
    }
}
/// <summary>
/// 定義變量用于接收
/// </summary>
public class SystemDateTime
{
    public short tYear;
    public short tMonth;
    public short tDayOfWeek;
    public short tDay;
    public short tHour;
    public short tMinute;
    public short tSecond;
    public short tMilliseconds;
}

以上就是本文所述的全部內(nèi)容了,希望大家能夠喜歡。

相關(guān)文章

最新評(píng)論