<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    從心開始

     

    系統(tǒng)時(shí)間修改方法

    java 修改系統(tǒng)時(shí)間方法

    第一種方法:

    需下載 jna.jar???????????????????????????

    a) 創(chuàng)建 Kernel32 接口

    package ?time.test;

    import ?com.sun.jna.Native;
    import ?com.sun.jna.Structure;
    import ?com.sun.jna.win32.StdCallLibrary;

    public ? interface ?Kernel32? extends ?StdCallLibrary
    {
    ????Kernel32?INSTANCE?
    = ?(Kernel32)Native.loadLibrary( " kernel32 " ,?Kernel32. class );
    ????
    public ?SYSTEMTIME?GetSystemTime();

    ????
    public ? void ?SetLocalTime(SYSTEMTIME?localTime);

    ????
    public ? static ? class ?SYSTEMTIME? extends ?Structure
    ????
    {
    ????
    // 必須有這么多個(gè)字段,按這個(gè)順序定義屬性
    ?
    ???????? public ? short ?wYear;
    ????????
    public ? short ?wMonth;
    ?????????????public?short?wDayOfWeek;
    ????????
    public ? short ?wDay;
    ????????
    public ? short ?wHour;
    ????????
    public ? short ?wMinute;
    ????????
    public ? short ?wSecond;
    ????????
    public ? short ?wMilliseconds;
    ???????
    ????}

    }

    b) 修改時(shí)間

    ?

    import ?time.test.Kernel32.SYSTEMTIME;


    public ? class ?SysTimeSettingDaoImp
    {
    ????
    protected ? void ?setLocalTime(String?time)
    ????
    {
    ??????
    // time時(shí)間格式是14位的字符串,如"20080108152130"
    ????????Short?year? = ?Short.parseShort(time.substring( 0 ,? 4 ));
    ????????Short?month?
    = ?Short.parseShort(time.substring( 4 ,? 6 ));
    ????????Short?day?
    = ?Short.parseShort(time.substring( 6 ,? 8 ));
    ????????Short?hour?
    = ?Short.parseShort(time.substring( 8 ,? 10 ));
    ????????Short?minute?
    = ?Short.parseShort(time.substring( 10 ,? 12 ));
    ????????Short?second?
    = ?Short.parseShort(time.substring( 12 ,? 14 ));

    ????????SYSTEMTIME?ss?
    = ? new ?SYSTEMTIME();
    ????????ss.setWYear(year);
    ????????ss.setWMonth(month);
    ????????ss.setWDay(day);
    ????????ss.setWHour(hour);
    ????????ss.setWMinute(minute);
    ????????ss.setWSecond(second);

    ????????Kernel32?lib?
    = ?Kernel32.INSTANCE;
    ????????lib.SetLocalTime(ss);
    ????}

    }

    第二種方法

    ?

    public ? class ?MyTimeClass
    {
    ????????????
    // timeAndDate格式位14位的字符串表示形式。
    ???????????? public ? void ?setLocalTime(String?timeAndDate)
    ????????????
    {
    ????????????????????????????String?date?
    = ?getDate(timeAndDate);
    ????????????????????????????String?time?
    = ?getTime(timeAndDate);
    ????????????
    ????????????????????????????
    // ?修改系統(tǒng)日期和時(shí)間
    ????????????????????????????Runtime.getRuntime().exec( " cmd?/c?date? " ? + ?date);
    ????????????????????????????Runtime.getRuntime().exec(
    " cmd?/c?time? " ? + ?time);
    ????????????}

    ????????????
    public ?String?getDate(String?timeAndDate)
    ????????????
    {
    ????????????????????String?year?
    = ?timeAndDate.substring( 0 ,? 4 );
    ????????????????????String?month?
    = ?timeAndDate.substring( 4 ,? 6 );
    ????????????????????String?day?
    = ?timeAndDate.substring( 6 ,? 8 );
    ????????????????????
    return ?year? + ? " - " ? + ?month? + ? " - " ? + ?day;
    ????????????}

    ????????????
    public ?String?getTime(String?timeAndDate)
    ????????????
    {
    ????????????????????String?hour?
    = ?timeAndDate.substring( 8 ,? 10 );
    ????????????????????String?minute?
    = ?timeAndDate.substring( 10 ,? 12 );
    ????????????????????String?second?
    = ?timeAndDate.substring( 12 ,? 14 );
    ????????????????????
    return ?hour? + ? " : " ? + ?minute? + ? " : " ? + ?second;
    ????????????}

    }

    Linux系統(tǒng)修改時(shí)間

    ??String?os? = ?System.getProperty( " os.name " ).toLowerCase(); // 獲取操作系統(tǒng)名稱

    if (os.indexOf( " windows " )? != ? - 1 )
    {
    ????cmd?
    = ? " cmd?/c?time? " ? + ?timeStr;
    ????ProcessUtil.printErr(Runtime.getRuntime().exec(cmd));
    ????cmd?
    = ? " cmd?/c?date? " ? + ?timeStr;
    ????ProcessUtil.printErr(Runtime.getRuntime().exec(cmd));
    ???}

    ???
    else
    ???
    {??
    ????cmd?
    = ? " date? " ? + ?timeStr; //timeStr時(shí)間到分,先寫時(shí)間再寫日期
    ????ProcessUtil.printErr(Runtime.getRuntime().exec(cmd));
    ???}


    public class ProcessUtil {
    ???
    ??? public static void printErr(Process p) {
    ??????? BufferedReader br = null;
    ??????? try {
    ??????????? br = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    ??????????? String line = null;
    ??????????? while ((line = br.readLine()) != null) {
    ??????????????? System.out.println(line);
    ??????????? }
    ??????? } catch (Exception e) {
    ??????????? e.printStackTrace();
    ??????? } finally {
    ??????????? try {
    ??????????????? if (br != null)
    ??????????????????? br.close();
    ??????????? } catch (Exception e) {
    ??????????????? e.printStackTrace();
    ??????????? }
    ??????????? p.destroy();
    ??????? }
    ??? }
    ???
    ??? public static void printConsole(Process p) {
    ??????? BufferedReader br = null;
    ??????? try {
    ??????????? br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    ??????????? String line = null;
    ??????????? while ((line = br.readLine()) != null) {
    ??????????????? System.out.println(line);
    ??????????? }
    ??????? } catch (Exception e) {
    ??????????? e.printStackTrace();
    ??????? } finally {
    ??????????? try {
    ??????????????? if (br != null)
    ??????????????????? br.close();
    ??????????? } catch (Exception e) {
    ??????????????? e.printStackTrace();
    ??????????? }
    ??????? }
    ??? }
    ???
    ??? public static String getErrInfo(Process p) {
    ??????? StringBuffer sb = new StringBuffer();
    ??????? BufferedReader br = null;
    ??????? try {
    ??????????? br = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    ??????????? String line = null;
    ??????????? while ((line = br.readLine()) != null) {
    ??????????????? sb.append(line).append("\n");
    ??????????? }
    ??????????? return sb.toString();
    ??????? } catch (Exception e) {
    ??????????? e.printStackTrace();
    ??????? } finally {
    ??????????? try {
    ??????????????? if (br != null)
    ??????????????????? br.close();
    ??????????? } catch (Exception e) {
    ??????????????? e.printStackTrace();
    ??????????? }
    ??????? }
    ??????? return null;
    ??? }

    }


    ?

    posted on 2008-01-08 23:47 飄雪 閱讀(1962) 評(píng)論(1)  編輯  收藏 所屬分類: JAVA技術(shù)

    評(píng)論

    # re: 系統(tǒng)時(shí)間修改方法 2008-09-19 09:33 jone

    good
      回復(fù)  更多評(píng)論   

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(1)

    隨筆分類(11)

    隨筆檔案(13)

    收藏夾

    firends

    搜索

    最新評(píng)論

    • 1.?re: udp及tcp穿越NAT
    • 您上述提到的是互聯(lián)網(wǎng)之間的公網(wǎng)與私網(wǎng)之間的NAT穿越,3g終端可以通過這種方式實(shí)現(xiàn)嗎?還有3g移動(dòng)設(shè)備的IP是動(dòng)態(tài)分配的,我怎么才能在公網(wǎng)服務(wù)器找到這個(gè)3G終端?
    • --svurm
    • 2.?re: udp及tcp穿越NAT
    • TCP穿越針對(duì)的是公網(wǎng)IP,而這個(gè)公網(wǎng)ip進(jìn)過幾個(gè)NAT,多少層映射到局域網(wǎng)客戶端上對(duì)大洞無影響,因?yàn)檫@些映射是nat完成的,一層,二層,三層,最終都映射到公網(wǎng)ip上,所以幾層NAT對(duì)打洞并無影響。
    • --lch
    • 3.?re: udp及tcp穿越NAT
    • 您好,感謝您提供的好介紹。請(qǐng)問:如果P2P的兩點(diǎn)之間,存在3-4個(gè)NAT,P2P也可以通起來嗎?從您對(duì)NAT的理解,如果通信兩端之間存在4個(gè)NAT,對(duì)那些應(yīng)用有影響?
    • --xujf
    • 4.?re: 系統(tǒng)時(shí)間修改方法
    • good
    • --jone
    • 5.?re: udp及tcp穿越NAT
    • 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
    • --...

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 亚洲国产综合第一精品小说| 美女被免费网站视频在线| 精品97国产免费人成视频| 欧美男同gv免费网站观看 | 亚洲另类古典武侠| 男女一进一出抽搐免费视频| 四虎影院免费在线播放| 亚洲视频一区在线播放| 巨胸狂喷奶水视频www网站免费| 日本一区二区三区日本免费| 亚洲欧洲日产国产最新| 国产一级淫片a免费播放口| 亚洲VA综合VA国产产VA中| 亚洲一级特黄特黄的大片| 88av免费观看| 亚洲精品国产精品乱码不卡√| 无码一区二区三区亚洲人妻| 无限动漫网在线观看免费| 亚洲美免无码中文字幕在线| 女人隐私秘视频黄www免费| 亚洲av日韩av欧v在线天堂| 亚洲最大中文字幕无码网站| 亚洲免费视频播放| 亚洲国产高清在线| 91在线免费观看| 久久亚洲AV无码西西人体| 色婷婷亚洲一区二区三区| 男人的好免费观看在线视频| 亚洲高清免费在线观看| 免费黄色电影在线观看| 国产亚洲AV夜间福利香蕉149 | 美女被免费网站视频在线| 日本视频免费在线| 亚洲精品无码mⅴ在线观看| 999久久久免费精品国产| 亚洲精品中文字幕无乱码| 久久国产免费一区二区三区| 国产亚洲成av片在线观看| 少妇性饥渴无码A区免费 | 国产免费黄色无码视频 | 亚洲人成色777777精品|