Modifier heure système

Résolu
asetti Messages postés 61 Date d'inscription jeudi 22 juillet 2004 Statut Membre Dernière intervention 15 mai 2010 - 19 juin 2009 à 09:17
asetti Messages postés 61 Date d'inscription jeudi 22 juillet 2004 Statut Membre Dernière intervention 15 mai 2010 - 19 juin 2009 à 10:21
Bonjour,

Je voudrais modifier l'heure système dans une appli java.
Après recherche, il s'avère que java ne comprend pas de fonction pour cela.
Comme mon appli ne sera utiliser que sur windows, j'essai donc de passer par la ligne de commande de la manière suivante :
Runtime.getRuntime().exec("cmd.exe /k Time 10:25:00");    (je vous évite les try)

J'obtiens alors le message
23 juin 2009 09:12:15 gestionheures.GestionHeuresView BoutonCorrespActionPerformed
GRAVE: null
java.io.IOException: Cannot run program "Time": CreateProcess error=2, Le fichier spécifié est introuvable
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
        at java.lang.Runtime.exec(Runtime.java:593)
        at java.lang.Runtime.exec(Runtime.java:431)
        at java.lang.Runtime.exec(Runtime.java:328)
        at gestionheures.ModifHeure.AppliqueDate(ModifHeure.java:35)
        at gestionheures.GestionHeuresView.BoutonCorrespActionPerformed(GestionHeuresView.java:401)
        at gestionheures.GestionHeuresView.access$800(GestionHeuresView.java:30)
        at gestionheures.GestionHeuresView$4.actionPerformed(GestionHeuresView.java:166)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6041)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
        at java.awt.Component.processEvent(Component.java:5806)
        at java.awt.Container.processEvent(Container.java:2058)
        at java.awt.Component.dispatchEventImpl(Component.java:4413)
        at java.awt.Container.dispatchEventImpl(Container.java:2116)
        at java.awt.Component.dispatchEvent(Component.java:4243)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
        at java.awt.Container.dispatchEventImpl(Container.java:2102)
        at java.awt.Window.dispatchEventImpl(Window.java:2440)
        at java.awt.Component.dispatchEvent(Component.java:4243)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Caused by: java.io.IOException: CreateProcess error=2, Le fichier spécifié est introuvable
        at java.lang.ProcessImpl.create(Native Method)
        at java.lang.ProcessImpl.(ProcessImpl.java:81)
        at java.lang.ProcessImpl.start(ProcessImpl.java:30)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
        ... 32 more

Est ce la commande qui n'est pas bonne?
Y a t il une autre solution pour modifier l'heure??

Winnie

1 réponse

asetti Messages postés 61 Date d'inscription jeudi 22 juillet 2004 Statut Membre Dernière intervention 15 mai 2010
19 juin 2009 à 10:21
Bon alors j'ai trouver
Au fait, je ne donnait pas la bonne commande ==> j'oubliait le cmd.exe de l'exemple ci-dessus

la commande Runtime.getRuntime().exec("cmd.exe /k Time "10:25:00"");
fonctionne donc parfaitement

idem pour la date :
Runtime.getRuntime().exec("cmd.exe /k Date "31/01/2009"");

Winnie
3
Rejoignez-nous