Date nowdate=new Date();
String date=nowdate.tolocalString();

解决方案 »

  1.   

    Date nowdate=new Date();
    String date=nowdate.tolocalString();
      

  2.   

    Date类中不是有相应的set方法吗?
      

  3.   

    谢谢大家的捧场。
    to shihongkitty(leejin) & Leemaasn(我给大家拜早年啦!新春快乐!!!) 
    我是想设置,而不是想获取。
      

  4.   

    关注!
    ICQ:348732090
    Yahoo:huangxinshui2002
      

  5.   

    to nobodyelse(空无一人) 
    date类的set方法只对本类有用,不能影响到本地机器时间。
      

  6.   

    采用备用方案解决了。
    用vc写了个小win32控制台程序。
    让后用java的runtime.getruntime().exec解决了。
    但是感觉很不是滋味,偶是个新手,
    希望有帮忙高手解决。
      

  7.   

    差不多
    应该可以直接调用WinAPI,这样你的控制台程序就可以省略了
    不过思路是相似的
    不过我没有用过jni,所以不知道怎么实现 ^_^
      

  8.   

    最后的解决方法。
    是:
    Runtime.getRuntime().exec("C:\\WINNT\\system32\\cmd /c date 2003-1-17");
    不用vc写的小控制台程序了。
    如果还有更好的方法的话,请告知。
      

  9.   

    以下是使用JNI实现的代码:package systemtime;public class CppExtention
    {
        private static native boolean cppSetSystemTime(int year,int month,int day,int hour,int minute,int second,int milliSecond);
        static
        {
            System.loadLibrary("CppExtention");
        }    public static boolean setSystemTime(int year,int month,int day,int hour,int minute,int second,int milliSecond)
        {
            return cppSetSystemTime(year,month,day,hour,minute,second,milliSecond);
        }
    }根据这个文件使用javah生成相关本地方法的头文件
    然后新建一个dll工程,实现相关本地方法,如下:
    // CppExtention.cpp : Defines the initialization routines for the DLL.
    //
    /////////////////////////////////////////////////////////////////////////////
    #include "stdafx.h"
    #include "CppExtention.h"#include "systemtime_CppExtention.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    /////////////////////////////////////////////////////////////////////////////
    // Message map
    /////////////////////////////////////////////////////////////////////////////
    BEGIN_MESSAGE_MAP(CCppExtentionApp, CWinApp)
    //{{AFX_MSG_MAP(CCppExtentionApp)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    /////////////////////////////////////////////////////////////////////////////
    // CCppExtentionApp construction
    /////////////////////////////////////////////////////////////////////////////
    CCppExtentionApp::CCppExtentionApp()
    {
    }
    /////////////////////////////////////////////////////////////////////////////
    // The one and only CCppExtentionApp object
    /////////////////////////////////////////////////////////////////////////////
    CCppExtentionApp g_cppExtentionApp;
    /////////////////////////////////////////////////////////////////////////////
    // The one and only CCppExtentionApp object
    /////////////////////////////////////////////////////////////////////////////
    JNIEXPORT jboolean JNICALL Java_systemtime_CppExtention_cppSetSystemTime
    (JNIEnv* pEnv,jclass jcls, jint year, jint month, jint day, 
     jint hour,jint minute, jint second, jint milliSecond)
    {
    SYSTEMTIME sysTime;
    GetSystemTime(&sysTime);  sysTime.wYear=(unsigned short)year;
    sysTime.wMonth=(unsigned short)month;
    sysTime.wDay=(unsigned short)day;
    sysTime.wHour=(unsigned short)hour;
    sysTime.wMinute=(unsigned short)minute;
    sysTime.wSecond=(unsigned short)second;
    sysTime.wMilliseconds=(unsigned short)milliSecond; FILETIME ft,ftLocal;
    SystemTimeToFileTime(&sysTime,&ftLocal);
    LocalFileTimeToFileTime(&ftLocal,&ft);
    FileTimeToSystemTime(&ft,&sysTime);

    return SetSystemTime(&sysTime);
    }
      

  10.   

    使用方法:
    package systemtime;public class SystemTime
    {
        public static void main(String[] args)
        {
            System.out.println(CppExtention.setSystemTime(2004,1,18,9,49,0,0));
        }
    }