Faking/Altering system time with JVM

odd question but...
Does anybody know of a way to fake/alter the system time read by the Data/System classes? For example, if I want to pretend it is next year. Can I alter the date for all applications running in that JVM? Feels like a jvm option (didn't find any that match up).
Realise that the clock on the machine (solaris) could be changed but I want to isolate the time shift to a particular JVM or Unix shell instance.
thanks / Matthew

Use Calendar and/or GregorianCalendar classes toset
and alter the date for a jvm.
What?! You can't do that.
>
You misunderstood my reply. I didn't say "modify your
system's clock", I said change the jvm's date - which
is internal to the jvm ONLY.IMHO you can not even do that with the methods of the calendar class.
you can only change the date of the calendar, not of the JVM.
As far as i can see, there is no way to change the time/date of the JVM.
The only thing you can do (as shankar.unni suggests) is to change the Systems date/time by using:
Runtime.getRuntime().exec(...)the limitations here are that
- you need to do this in a operating system specific way
- on windows it might be possible that you even have to do it in a language specific way (german win2K takes SimpleDateFormat("dd.mm.YYYY"))
- you have to have the privileges to change the date.

Similar Messages

  • How to compare the current system time with two timing?

    want to get the current system time and compare with the two different timing example startwindow time as 2:00:00AM and endWindowTime as 6:00:00AM. if my current system time falls between these window i have to execute my rest of the code.
    my below code works for fine for JAVA 1.6 version when i do the same code with JAVA 1.4 i am getting different date and time
    String starTime=(String) NightlyvendorStatus[0].getPropertyValue("startTime");
      String endTime=(String) NightlyvendorStatus[0].getPropertyValue("endTime");
      Date windowStarttime = new SimpleDateFormat("HH:mm:ss").parse(starTime);
      Date windowEndtime = new SimpleDateFormat("HH:mm:ss").parse(endTime);
      Date systemdate = new Date();
      SimpleDateFormat parser = new SimpleDateFormat("HH:mm:ss");
      String systemTime=parser.format(systemdate);
      Date currentTime = new SimpleDateFormat("HH:mm:ss").parse(systemTime);
      if (currentTime.after(windowStarttime) && currentTime.before(windowEndtime)){
    --- rest logic here---}
    the output from JAVA 1.4 IS Thu Jan 01 02:00:00 GMT 1970 Thu Jan 01 06:00:00 GMT 1970 Thu Jan 01 03:23:00 GMT 1970
    HOW TO DO this logic..

    Hi,
    You can try converting dates into timestamp and compare just like as comparing two integers variables.
    Regards,
    Anshul

  • Re: incrementing the current system time with 30 minutes

    hi
    in JSPinner i need to display the time but that time should be 30 min greater than system time
    is that possible
    reg
    vino

    1. Create a GregorianCalendar instance
    2. Use roll() to add 30 minutes
    3. Use getTime() to convert to a Date instance

  • Updating system time with simple operator interface

    Hello,
    I need to update system time on the simple OI but when I use "Get system time and date.vi". The indicator on the front panel doesn't get updated every second, there is delay of atleast 5 secs. I tried using parallel while Loop method as well but still the problem persist
    Any ideas guys?
    Regards
    Prav
    Solved!
    Go to Solution.

    See attached simple OI modified to display time and date. When I run It, the update on indicator is like this 16:21:04-->16:21:09 (delay of 5 secs).I tried in time out event as well but no sucesss.
    Attachments:
    example.vi ‏69 KB

  • Setting the system time with only Java.

    Am trying trying to write a 100% pure java Alarm Clark. One feature I wish to have is to syncronize with the atomic clock.
    Is this possible in Java. All I have been able to find is system dependent ways to do it through exec.
    Thank you,
    Jacob

    What do you mean "atomic clock"? Do you wish to synchronize your alarm clock with GMT? If so, you can directly access the National Institute of Standards and Technology's atomic clock on-line...see the site :
    http://www.boulder.nist.gov/timefreq/service/its.htm
    You could then get the local time from the computer, thus appropriately adjusting your clock. Synchronizing your system clock to the atomic clock is system-dependent, as mentioned by the other respondent.

  • Simulating of system time for JVM

    I have following problem:
    There is a big system written in Java, which needs to be tested automatically. There are test cases, which concern events in the future - in a few days, months, etc. That means, some initial state of the system can be prepared today (with some input data, like request or file) and then in the production environment one would have to wait eg. 1 month for some event to occur automatically - when the tested system detects that the given date lies in the past already. Of course it's not acceptable to wait 1 month before the testcase is finished, so some workaround is needed.
    There are no changes to the code of the tested system allowed - it must be tested as blackbox. Changing of system date on the OS level is neither an option.
    My question is: is it possible to start somehow the virtual machine with predefined fake date - not the real system date. So that all methods using system date (like Date() constructor etc.) get this fake date as input instead of real system date.
    An example to be more precise:
    When I call:
    java -fake_sysdate01.01.2010T12:25:00 com.company.system.main
    the new Date() sets the Date object to above date + delta seconds, which ticked from the start. So if the "new Date()" would be executed 15 minutes after start of the programme, it would be initiated with 01.01.2010T12:40:00 instead of the real current date.
    Any ideas? Do I have to write my own virtual machine with such an option or is there some simplier solution? :-)

    Yeah I just noticed, now I'm wondering why not?Quite simple: it must be possible to run the tests
    automatically on Sun or Linux machines, where the
    tester is not the only person working and has noroot
    privileges as well. So changing of system date isnot
    possible (no privileges) and also not allowed(other
    processes, tests etc. would not be happy if system
    date would be changed each few minutes or so :-)One does not test in "production". A more suitable
    approach is to have "sandbox" test environments,
    where you can alter the environment without
    affecting real productional systems.Of course not. One test on machines, which are dedicated for tests only. But not for just one tester. And such actions like changing of the system date are not allowed, because they would disturb in other tests.

  • How to initialize System time?

    Hello everybody.
    I'm working with a Siemens TC65.
    I work without battery. When I supply the module, I get from System.currentTimeMillis() this value: 1009843232546, which I think corresponds to Tue Jan 01 00:00:32 UTC 2002.
    Obviously, I wish to set the correct system time.
    Does anybody knows how to set the system time?
    Thanks in advance.
    Message was edited by:
    Jordi_E

    I am experiencing the exact same problem. I am synchronising
    my time with an sntp server and setting the tc65 system time
    with AT+CCLK.
    Unfortunately System.currentTimeMillis() is still showing the old time,
    even after waiting up to 10s after AT+CCLK. So how do I get it to show
    the new correct time?
    Problem is I cannot restart the module everytime the time is set because
    I need to listen to incoming data.
    Any suggestion would be really helpful. Thanks

  • How to check the current time with a Stored  time in string format

    Hi All
    I would like to compare the system time with an existing time values which is allready there in String format..
    i mean i would like to check if the SysTime is inbetween 6:30 and 14:00
    I accomplished this in Oracle ..
    Select 'Y' from dual where to_date(to_char(sysdate,'HH24:MI '),'HH24:MI') between to_date('06:30','HH24:MI') and to_date('14:00','HH24:MI')
    But instead of checking the DB each and every time , the perfomance would be better if we can do this in our java code..
    Could some one provide me with a code to accomplish the above scenario..
    Thanks in advance..,.,

    import java.util.Calendar;
    Calendar rightNow = Calendar.getInstance();  // gets the current date and time to millisec
    Calendar earlyTime = Calendar.getInstance().set(Calendar.HOUR_OF_DAY, 6).set(Calendar.MINUTE, 30);
    Calendar lateTime = Calendar.getInstance().set(Calendar.HOUR_OF_DAY, 8).set(Calendar.MINUTE, 0);
    if (rightNow.compareTo(earlyTime)> 0 && rightNow.compareTo(lateTime) < 0){
    // do something
    }Try this.

  • I want to get and set windows system time through lab view

    Hi
    I want to get and set windows system time with the help of lab view 8.5.
    please help me out.
    ekanth

    You can use the call library function node. Once you drop it on your block diagram double click it and you will be able to select the dllyou want to use. Choose kernel32.dll and you will see methods listed called getsystemtime and setsystemtime. Use those
    CLA, LabVIEW Versions 2010-2013

  • System time in microseconds

    The static method System.currentTimeMillis() give us the system time in milliseconds. Is there any method that can give us the system time with a microscond resolution ?
    Thanks for your attention.
    Bruno.

    The system time is not even accurate in milliseconds on many operating systems. In Windows, I think it is only accurate to 50 milliseconds.

  • Timer problems on Linux changing system time and data

    On Linux SO,
    both with flash player plugin and standalone flash player, setting system time with command:
    date -s 11:11:11
    hang timers (flash.utils.Timer) immediately!

    I notice that updating system time (both with "date -s hh:mm:ss" and through ntpd) with a new time in the future doesn't hang up flash.utils.Timer component.
    Contrary, if I update system time with a past new one, flash.utils.Timer stops work immediately!!!
    This is huge problem for those interfaces that need to run for a long time and also need to be time updated (for examplem through ntp daemon).
    Can anyone help me?
    PS: Windows Flashplayer doesn't have this problem !!

  • Regarding Sun Java System Application Server Issue with JVM

    Regarding Sun Java System Application Server Issue with JVM
    Hi
    I have installed SJSAS9.1 on solaris system. I m trying to deploy war file which i compiled in windows enviorment by jdk1.5.0_05. Every time i got the following error :
    type Exception report
    message
    descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: PWC6033: Unable to compile class for JSP
    PWC6199: Generated servlet error:
    [javac] javac: invalid target release: 1.5
    [javac] Usage: javac
    [javac] where possible options include:
    [javac] -g Generate all debugging info
    [javac] -g:none Generate no debugging info
    [javac] -g:{lines,vars,source} Generate only some debugging info
    [javac] -nowarn Generate no warnings
    [javac] -verbose Output messages about what the compiler is doing
    [javac] -deprecation Output source locations where deprecated APIs are used
    [javac] -classpath Specify where to find user class files
    [javac] -sourcepath Specify where to find input source files
    [javac] -bootclasspath Override location of bootstrap class files
    [javac] -extdirs Override location of installed extensions
    [javac] -d Specify where to place generated class files
    [javac] -encoding Specify character encoding used by source files
    [javac] -source Provide source compatibility with specified release
    [javac] -target Generate class files for specific VM version
    [javac] -help Print a synopsis of standard options
    note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1 logs.
    I have cheked jvm version on both system the only difference is :
    Solaris points to jdk 1.5.0_09
    Windows point to jdk1.5.0_05
    Even i tried to run blank jsp also but again i got the same error.
    Can any help me to sort out the problem or give me any idea so i can do something by my own.
    Thanks in Advance
    Gagan

    Do you have ANT installed and available?
    Thanks,
    Kedar

  • Changing the System time in the JVM where Weblogic runs

    Hi,
    I am trying to change the System time where the Web-logic server (11g) runs using Mocking. I use "jmockit.jar" to mock the System.class. A Spring bean is created and through that I try to change the System time. I need to change the time for testing scenarios. For example, I need to backdate and do the testing for some scenarios. For the moment I do this manually and I want to automate this by changing only the time in the JVM where the application server runs. When I try to automate this using the Spring bean, I get an error as follows. Do anyone have any idea about this.
    [WLServer adminserver] Exception in thread "Timer-5" java.lang.IllegalArgumentException: No class with name "com.abc.common.service.impl.MockSystem" found
    [WLServer adminserver] at mockit.internal.util.Utilities.loadClass(Utilities.java:71)
    [WLServer adminserver] at mockit.internal.MockingBridge.callMock(MockingBridge.java:156)
    [WLServer adminserver] at mockit.internal.MockingBridge.invoke(MockingBridge.java:85)
    [WLServer adminserver] at java.lang.System.currentTimeMillis(System.java)
    [WLServer adminserver] at java.util.TimerThread.mainLoop(Timer.java:495)
    [WLServer adminserver] at java.util.TimerThread.run(Timer.java:462)
    [WLServer adminserver] Exception in thread "DynamicListenThread[Default]" java.lang.IllegalArgumentException: No class with name "com.common.service.impl.MockSystem" found
    [WLServer adminserver] at mockit.internal.util.Utilities.loadClass(Utilities.java:71)
    [WLServer adminserver] at mockit.internal.MockingBridge.callMock(MockingBridge.java:156)
    [WLServer adminserver] at mockit.internal.MockingBridge.invoke(MockingBridge.java:85)
    [WLServer adminserver] at java.lang.System.currentTimeMillis(System.java)
    [WLServer adminserver] at java.util.logging.LogRecord.<init>(LogRecord.java:139)
    [WLServer adminserver] at com.bea.logging.BaseLogRecord.<init>(BaseLogRecord.java:33)
    [WLServer adminserver] at com.bea.logging.BaseLogRecord.<init>(BaseLogRecord.java:48)
    [WLServer adminserver] at com.bea.logging.BaseLogRecord.<init>(BaseLogRecord.java:70)
    [WLServer adminserver] at weblogic.logging.WLLogRecord.<init>(WLLogRecord.java:63)
    [WLServer adminserver] at weblogic.logging.JDKLoggerFactory.createBaseLogRecord(JDKLoggerFactory.java:74)
    [WLServer adminserver] at com.bea.logging.LoggingService.log(LoggingService.java:216)
    [WLServer adminserver] at weblogic.server.ServerLogger.logListenThreadFailure(ServerLogger.java:205)
    [WLServer adminserver] at weblogic.server.channels.DynamicListenThread.run(DynamicListenThread.java:197)
    [WLServer adminserver] at java.lang.Thread.run(Thread.java:619)
    [WLServer adminserver] Exception in thread "weblogic.timers.TimerThread" java.lang.IllegalArgumentException: No class with name "com.abc.common.service.impl.MockSystem" found
    [WLServer adminserver] at mockit.internal.util.Utilities.loadClass(Utilities.java:71)
    [WLServer adminserver] at mockit.internal.MockingBridge.callMock(MockingBridge.java:156)
    [WLServer adminserver] at mockit.internal.MockingBridge.invoke(MockingBridge.java:85)
    [WLServer adminserver] at java.lang.System.currentTimeMillis(System.java)
    [WLServer adminserver] at weblogic.timers.internal.TimerThread$Thread.run(TimerThread.java:256)
    [WLServer adminserver] Exception in thread "Timer-4" java.lang.IllegalArgumentException: No class with name "com.abc.common.service.impl.MockSystem" found
    [WLServer adminserver] at mockit.internal.util.Utilities.loadClass(Utilities.java:71)
    [WLServer adminserver] at mockit.internal.MockingBridge.callMock(MockingBridge.java:156)
    [WLServer adminserver] at mockit.internal.MockingBridge.invoke(MockingBridge.java:85)
    [WLServer adminserver] at java.lang.System.currentTimeMillis(System.java)
    [WLServer adminserver] at java.util.TimerThread.mainLoop(Timer.java:495)
    [WLServer adminserver] at java.util.TimerThread.run(Timer.java:462)
    [WLServer adminserver] Exception in thread "ClusterNode-localhost" java.lang.IllegalArgumentException: No class with name "com.abc.common.service.impl.MockSystem" found
    [WLServer adminserver] at mockit.internal.util.Utilities.loadClass(Utilities.java:71)
    [WLServer adminserver] at mockit.internal.MockingBridge.callMock(MockingBridge.java:156)
    [WLServer adminserver] at mockit.internal.MockingBridge.invoke(MockingBridge.java:85)
    [WLServer adminserver] at java.lang.System.currentTimeMillis(System.java)
    [WLServer adminserver] at EDU.oswego.cs.dl.util.concurrent.Latch.attempt(Unknown Source)
    [WLServer adminserver] at org.apache.jackrabbit.core.cluster.ClusterNode.run(ClusterNode.java:261)
    [WLServer adminserver] at java.lang.Thread.run(Thread.java:619)
    [WLServer adminserver] Exception in thread "Timer-1" java.lang.IllegalArgumentException: No class with name "com.abc.common.service.impl.MockSystem" found
    [WLServer adminserver] at mockit.internal.util.Utilities.loadClass(Utilities.java:71)
    [WLServer adminserver] at mockit.internal.MockingBridge.callMock(MockingBridge.java:156)
    [WLServer adminserver] at mockit.internal.MockingBridge.invoke(MockingBridge.java:85)
    [WLServer adminserver] at java.lang.System.currentTimeMillis(System.java)
    [WLServer adminserver] at java.util.TimerThread.mainLoop(Timer.java:495)
    [WLServer adminserver] at java.util.TimerThread.run(Timer.java:462)
    [WLServer adminserver] Exception in thread "ClusterNode-localhost" java.lang.IllegalArgumentException: No class with name "com.abc.common.service.impl.MockSystem" found
    [WLServer adminserver] at mockit.internal.util.Utilities.loadClass(Utilities.java:71)
    [WLServer adminserver] at mockit.internal.MockingBridge.callMock(MockingBridge.java:156)
    [WLServer adminserver] at mockit.internal.MockingBridge.invoke(MockingBridge.java:85)
    [WLServer adminserver] at java.lang.System.currentTimeMillis(System.java)
    [WLServer adminserver] at EDU.oswego.cs.dl.util.concurrent.Latch.attempt(Unknown Source)
    [WLServer adminserver] at org.apache.jackrabbit.core.cluster.ClusterNode.run(ClusterNode.java:261)
    [WLServer adminserver] at java.lang.Thread.run(Thread.java:619)
    [WLServer adminserver] Exception in thread "Timer-2" java.lang.IllegalArgumentException: No class with name "com.abc.common.service.impl.MockSystem" found
    [WLServer adminserver] at mockit.internal.util.Utilities.loadClass(Utilities.java:71)
    [WLServer adminserver] at mockit.internal.MockingBridge.callMock(MockingBridge.java:156)
    [WLServer adminserver] at mockit.internal.MockingBridge.invoke(MockingBridge.java:85)
    [WLServer adminserver] at java.lang.System.currentTimeMillis(System.java)
    [WLServer adminserver] at java.util.TimerThread.mainLoop(Timer.java:495)
    [WLServer adminserver] at java.util.TimerThread.run(Timer.java:462)
    [WLServer adminserver] Exception in thread "weblogic.time.TimeEventGenerator" java.util.MissingResourceException: Can't locate bundle for class 'weblogic.common.T3MiscLogLocalizer'
    [WLServer adminserver] at weblogic.i18ntools.L10nLookup.getLocalizer(L10nLookup.java:427)
    [WLServer adminserver] at weblogic.i18n.logging.CatalogMessage.<init>(CatalogMessage.java:47)
    [WLServer adminserver] at weblogic.common.T3MiscLogger.logThrowable(T3MiscLogger.java:325)
    [WLServer adminserver] at weblogic.time.common.internal.TimeEventGenerator.run(TimeEventGenerator.java:126)
    [WLServer adminserver] at java.lang.Thread.run(Thread.java:619)
    OR
    Do anyone know any other way to overcome this issue using some other mocking jar.
    Thanks
    Edited by: 913136 on Feb 8, 2012 2:32 AM

    Hi,
    I could manage to change the time in JVM where the Weblogic server runs. I loaded an Spring bean from my Test class and from that bean I set an offset (to shift the time) in the Mock class (say, MockSystem class). In this case I used the jmockit implementation for instrumentation purposes. The MockSystem class should not be instantiated by us and jmockit takes care of that part. What I had to do was defining the javaagent and another parameter ("-Djmockit-mocks=com.abc.common.service.impl.MockSystem") in the Weblogic server build XML (mentioned in the following URL[1]). But to work this the MockSystem.class file should be wrapped in a JAR file and included in Weblogic server/lib directory and define it in the Weblogic build XML file as a classpath. For more explanations visit this URL [2].
    [1]. http://jmockit.googlecode.com/svn/trunk/www/javadoc/mockit/Mockit.html#setUpStartupMocks%28java.lang.Object...%29
    [2]. http://code.google.com/p/jmockit/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Tool%20Type%20Status%20Priority%20Summary&groupby=&sort=&id=207
    Thanks
    -thiwanka-

  • Set  Substitution Variables automaticaly with system time?

    does anyone know of a utility or a method to automatically update substitution variables with the system time?[email protected]

    Hi, another solution with maxl under NT, using environment variables:create a file test.msh:spool on to c:\test.out;login $1 $2 on $3; alter database $4 set variable $5 $6;echo "variable altered";spool off;exit;and launch via the command prompt:essmsh test.msh admin password localhost Demo.Basic datetime '%TIME%'for the date for instance:essmsh test.msh admin password localhost Demo.Basic datetime '\""%DATE%\""'Eric BelmonPartake Consulting.

  • Jvm time 1 hour behind system time

    hi
    I'm running java on hp-ux 11.11
    since the system time has changed to dst, the java applications are still showing the old time (1 hour behind)
    for example
    now.get(Calendar.YEAR)+"/"+now.get(Calendar.MONTH)+"/"+now.get(Calendar.DATE)+" "+now.get(Calendar.HOUR)+":"+now.get(Calendar.MINUTE)+":"+now.get(Calendar.SECOND)+":"+now.get(Calendar. MILLISECOND)
    will give the output
    2005/7/16 1:28:58:905
    and the tcsh date command will give the output
    Tue Aug 16 13:28:58 IDT 2005
    any ideas on how to synchronize the jvm time with system time?
    thanks
    Yiftah

    I can only confirm that's its true for me too. I was ok on Win98 but shows up on WinXP with summer time (during winter time it was ok. )

Maybe you are looking for