Article View: borland.public.jbuilder.java.language
Article #15145Re: changing the system date on a Windows machine
From: Tor Iver Wilhelmsen
Date: Thu, 01 Jul 1999 00:00
Date: Thu, 01 Jul 1999 00:00
36 lines
1974 bytes
1974 bytes
"Jason Singer" <jintsjason@worldnet.att.net> writes:
> The bat file has a dos date command in it. I would like to do it directly
> from Java. Is it possible? Does anybody know how?
Well, if you want windows-only, and can use the Microsoft JVM, try
this:
import com.ms.win32.*;
//...
public void setWin32Time(java.util.Calendar time) {
SYSTEMTIME winTime = new SYSTEMTIME();
winTime.wYear = (short) time.get(Calendar.YEAR);
winTime.wMonth = (short) time.get(Calendar.MONTH);
winTime.wDayOfWeek = (short) time.get(Calendar.DAY_OF_WEEK);
winTime.wDay = (short) time.get(Calendar.DAY_OF_MONTH);
winTime.wHour = (short) time.get(Calendar.HOUR_OF_DAY);
winTime.wMinute = (short) time.get(Calendar.MINUTE);
winTime.wSecond = (short) time.get(Calendar.SECOND);
winTime.wMilliseconds = (short) time.get(Calendar.MILLISECOND);
Kernel32.SetSystemTime(winTime);
}
Both the SYSTEMTIME "struct" class and the Kernel32 J/Direct mapping
class are part of the com.ms.win32 package. To use them in JBuilder,
you need to make a library for the classes by looking through the zip
files in %windir%\Java\Packages and select the ones that have
MS-specific classes in them.
Note: You cannot run this directly from JBuilder, unless you make a
BAT file to invoke jview.exe. Also, if you want to do this from an
applet, it waill only work in MSIE, and you need to request the
privilege using some obscure com.ms.security classes.
Technical Details
Message-ID:
<u7lokkdgg.fsf@sds.no>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7ldavv$rn314@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,a6884cbfc0ca74bf X-Google-Attributes: gidf74b3,public From: Tor Iver Wilhelmsen <tor.wilhelmsen@sds.no> Subject: Re: changing the system date on a Windows machine Date: 1999/07/01 Message-ID: <u7lokkdgg.fsf@sds.no> X-Deja-AN: 495932581 Sender: towi@SDSA1761 References: <7ldavv$rn314@forums.borland.com> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.language